From 1a6d9acc3177a5f1bb200b532ef6cae624cb339e Mon Sep 17 00:00:00 2001 From: Wojciech Chrobot Date: Thu, 5 Oct 2017 15:32:48 +0200 Subject: [PATCH 01/16] Reduce Capabilities set of tef-simulator to none. During installation set simulator as a tef backend using tef_update.sh. Reduce root user. Currently user is the security_fw user and group. Change ownership of /usr/lib/tastore directory and helloworld TA to security_fw. Change permissions to user/group/others of helloworld TA and tastore directory. Change-Id: I6fa65ba97d82784968134be58a60e7a435d90b38 --- CMakeLists.txt | 4 +++- TEECLib/CMakeLists.txt | 1 + include/include/config.h | 8 +++++++- packaging/tef-simulator-helloworld.spec | 4 ++-- packaging/tef-simulator.spec | 22 ++++++++++++++++------ simulatordaemon/CMakeLists.txt | 2 ++ .../src/TABinaryManager/TABinaryManager.cpp | 4 ++-- systemd/tef-simulator.service.in | 5 +++-- 8 files changed, 36 insertions(+), 14 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0273513..133c2ca 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -48,6 +48,8 @@ ADD_DEFINITIONS("-Werror") # Make all warnings into errors. #ADD_DEFINITIONS("-Wall") # Generate all warnings #ADD_DEFINITIONS("-Wextra") # Generate even more extra warnings +ADD_DEFINITIONS("-D_ARCH_=${ARCH}") + # Enable tizen-specific preprocessor defines IF(DEFINED TIZEN) ADD_DEFINITIONS("-D__TIZEN__") @@ -71,7 +73,7 @@ SET(TARGET_TEF_SIMULATOR_DAEMON ${TARGET_TEF_SIMULATOR}-daemon) SET(TARGET_TEF_SIMULATOR_SSFLIB ${TARGET_TEF_SIMULATOR}-ssflib) # below targets need different names due to linking with CAs and TAs (libteec for client) -SET(TARGET_TEF_SIMULATOR_TEEC_LIB teec) +SET(TARGET_TEF_SIMULATOR_TEEC_LIB ${TARGET_TEF_SIMULATOR}-teec) SET(TARGET_TEF_SIMULATOR_TEE_STUB TEEStub) ############################# sub-project paths ############################### diff --git a/TEECLib/CMakeLists.txt b/TEECLib/CMakeLists.txt index 94f92c8..c153bfa 100644 --- a/TEECLib/CMakeLists.txt +++ b/TEECLib/CMakeLists.txt @@ -32,6 +32,7 @@ SET(TEEC_LIB_SOURCES ADD_LIBRARY(${TARGET_TEF_SIMULATOR_TEEC_LIB} SHARED ${TEEC_LIB_SOURCES} ) +SET_TARGET_PROPERTIES(${TARGET_TEF_SIMULATOR_TEEC_LIB} PROPERTIES LIBRARY_OUTPUT_NAME teec) ADD_DEPENDENCIES(${TARGET_TEF_SIMULATOR_TEEC_LIB} ${TARGET_TEF_SIMULATOR_OSAL} diff --git a/include/include/config.h b/include/include/config.h index 2a1daab..b72f61f 100644 --- a/include/include/config.h +++ b/include/include/config.h @@ -24,6 +24,12 @@ #define TEE_PROP_FILE "/usr/bin/GPD_TEE_PROP" #define TA_ROOT "/tmp/" -#define TEE_TASTORE_ROOT "/usr/lib/tastore/" +#if _ARCH_ == 32 + #define TEE_TASTORE_ROOT "/usr/lib/tastore/" +#elif _ARCH_ == 64 + #define TEE_TASTORE_ROOT "/usr/lib64/tastore/" +#else + #error "Invalid architecture was set!" +#endif #endif /* INCLUDE_CONFIG_H_ */ diff --git a/packaging/tef-simulator-helloworld.spec b/packaging/tef-simulator-helloworld.spec index c446ff8..ae4b8d4 100644 --- a/packaging/tef-simulator-helloworld.spec +++ b/packaging/tef-simulator-helloworld.spec @@ -50,5 +50,5 @@ make install %postun %files -n %{name} -%{bin_dir}/tef-simulator-helloworld -%{tastore_dir}/00000000000000000000112233445566 +%attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-helloworld +%attr(444,security_fw,security_fw) %{tastore_dir}/00000000000000000000112233445566 diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index f7fb586..49bb866 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -83,6 +83,7 @@ cmake . \ -DPKGCFG_PREFIX=/usr \ -DPKGCFG_VERSION=%{version} \ -DSMACK_DOMAIN_NAME=%{smack_domain_name} \ + -DARCH=%{__isa_bits} \ -DTIZEN=1 make %{?jobs:-j%jobs} @@ -92,21 +93,30 @@ make install %pre %post +systemctl enable tef-simulator + +%post -n %{name}-client +tef-update.sh simulator %preun %postun -tef-update.sh + +%postun -n %{name}-client +if [ $1 = 0 ] ; then + tef-update.sh +fi %files -n %{name} -%{bin_dir}/tef-simulator-daemon +%attr(111,security_fw,security_fw) %{bin_dir}/tef-simulator-daemon %{lib_dir}/libtef-simulator-ssflib.so -%{_unitdir}/tef-simulator.service -%{_unitdir}/tef-simulator.socket -%{_unitdir}/tef-simulator.target +%attr(770,root,security_fw) %{tastore_dir} +%attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.service +%attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.target +%attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.socket %files -n %{name}-client -%{lib_dir}/tef/simulator +%attr(111,security_fw,security_fw) %{lib_dir}/tef/simulator/libteec.so %files -n %{name}-devkit %{bin_dir}/TA_PackageBuilder.sh diff --git a/simulatordaemon/CMakeLists.txt b/simulatordaemon/CMakeLists.txt index 54aa690..033b098 100644 --- a/simulatordaemon/CMakeLists.txt +++ b/simulatordaemon/CMakeLists.txt @@ -103,3 +103,5 @@ TARGET_LINK_LIBRARIES(${TARGET_TEF_SIMULATOR_DAEMON} ) INSTALL(TARGETS ${TARGET_TEF_SIMULATOR_DAEMON} DESTINATION ${BIN_DIR}) + +INSTALL(DIRECTORY DESTINATION ${TASTORE_DIR}) diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp index d7b3b79..f0cae26 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.cpp @@ -190,9 +190,9 @@ bool TABinaryManager::initTAatPath(const string &path, const string &uuid) { */ void TABinaryManager::decryptImage(StructBinaryInfo& info) { string cipher = "-aes-256-cbc"; - string secret = base64_decode (info.manifest.taencryption.model.plainkeydata); + string secret = base64_decode(info.manifest.taencryption.model.plainkeydata); string keyhashFilename = info.imagePath + ".keyhash"; - secret.erase(secret.size()-2); + secret.erase(secret.size() - 2); string keyHash = "echo -n " + secret + " | openssl dgst -sha256 | awk '{print $2}' > " + keyhashFilename; int result = system(keyHash.c_str()); if (result != 0) { diff --git a/systemd/tef-simulator.service.in b/systemd/tef-simulator.service.in index 4c55561..85496a0 100644 --- a/systemd/tef-simulator.service.in +++ b/systemd/tef-simulator.service.in @@ -3,8 +3,9 @@ Description=TEF Simulator Daemon DefaultDependencies=no [Service] -User=root -Group=root +User=security_fw +Group=security_fw +CapabilityBoundingSet= SmackProcessLabel=@SMACK_DOMAIN_NAME@ ExecStart=@SYSTEMD_CFG_BIN_DIR@/tef-simulator-daemon Sockets=tef-simulator.socket -- 2.7.4 From ef3e6532317f005d3ec09d0da390a254eb710752 Mon Sep 17 00:00:00 2001 From: "r.tyminski" Date: Tue, 17 Oct 2017 12:13:01 +0200 Subject: [PATCH 02/16] Link tastore directory to /opt. Simulator unpack TA, by create directory in TA path. We need to move tastore directory to the path with write permissions. Change-Id: I06c73e2236ac01add896f4fc428a2d6b009d0156 --- packaging/tef-simulator-helloworld.spec | 1 - packaging/tef-simulator.spec | 4 +++- simulatordaemon/src/TABinaryManager/TABinaryManager.h | 1 - 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packaging/tef-simulator-helloworld.spec b/packaging/tef-simulator-helloworld.spec index ae4b8d4..e4a8b4a 100644 --- a/packaging/tef-simulator-helloworld.spec +++ b/packaging/tef-simulator-helloworld.spec @@ -33,7 +33,6 @@ cd helloworld cmake . \ -DCMAKE_BUILD_TYPE=%{?build_type:%build_type}%{!?build_type:RELEASE} \ -DBIN_DIR=%{build_bin_dir} \ - -DINCLUDE_DIR=%{include_dir} \ -DTASTORE_DIR=%{build_tastore_dir} make %{?jobs:-j%jobs} diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index 49bb866..3ce274c 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -25,7 +25,8 @@ PreReq: tef-libteec %define lib_dir %{?TZ_SYS_LIB:%TZ_SYS_LIB}%{!?TZ_SYS_LIB:%_libdir} %define data_dir %{?TZ_SYS_RO_SHARE:%TZ_SYS_RO_SHARE}%{!?TZ_SYS_RO_SHARE:%_datadir} %define include_dir %{?TZ_SYS_INCLUDE:%TZ_SYS_INCLUDE}%{!?TZ_SYS_INCLUDE:%_includedir} -%define tastore_dir %{lib_dir}/tastore +%define tastore_dir /opt/tastore +%define link_tastore_dir %{lib_dir}/tastore %define build_bin_dir %{buildroot}%{bin_dir} %define build_lib_dir %{buildroot}%{lib_dir} @@ -93,6 +94,7 @@ make install %pre %post +ln -sf %{tastore_dir} %{link_tastore_dir} systemctl enable tef-simulator %post -n %{name}-client diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.h b/simulatordaemon/src/TABinaryManager/TABinaryManager.h index ab852b8..c1149de 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.h +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.h @@ -38,7 +38,6 @@ #include "tee_client_api.h" #include "TAManifest.h" #include "TAUnpack.h" -#include "Config.h" #include "tee_internal_api.h" using namespace std; -- 2.7.4 From 158fa45ab469b207d91a1788e955e1a7f384deb4 Mon Sep 17 00:00:00 2001 From: "r.tyminski" Date: Tue, 17 Oct 2017 12:17:00 +0200 Subject: [PATCH 03/16] Modify tef-simulator service and socket to start at boot. Bind service and socket to each other to stop one when use stop other. Change-Id: Ib94f4eb99508f6165df3cba40b333f2180a2bf9f --- packaging/tef-simulator.spec | 1 - systemd/CMakeLists.txt | 1 - systemd/tef-simulator.service.in | 2 +- systemd/tef-simulator.socket | 5 +---- systemd/tef-simulator.target | 4 ---- 5 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 systemd/tef-simulator.target diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index 3ce274c..1f34aef 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -114,7 +114,6 @@ fi %{lib_dir}/libtef-simulator-ssflib.so %attr(770,root,security_fw) %{tastore_dir} %attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.service -%attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.target %attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.socket %files -n %{name}-client diff --git a/systemd/CMakeLists.txt b/systemd/CMakeLists.txt index 40e4602..57f288d 100644 --- a/systemd/CMakeLists.txt +++ b/systemd/CMakeLists.txt @@ -22,7 +22,6 @@ CONFIGURE_FILE(${CMAKE_SOURCE_DIR}/systemd/tef-simulator.service.in INSTALL(FILES ${CMAKE_SOURCE_DIR}/systemd/tef-simulator.service - ${CMAKE_SOURCE_DIR}/systemd/tef-simulator.target ${CMAKE_SOURCE_DIR}/systemd/tef-simulator.socket DESTINATION ${SYSTEMD_UNIT_DIR} diff --git a/systemd/tef-simulator.service.in b/systemd/tef-simulator.service.in index 85496a0..85a3efa 100644 --- a/systemd/tef-simulator.service.in +++ b/systemd/tef-simulator.service.in @@ -1,6 +1,7 @@ [Unit] Description=TEF Simulator Daemon DefaultDependencies=no +BindsTo=tef-simulator.socket [Service] User=security_fw @@ -8,7 +9,6 @@ Group=security_fw CapabilityBoundingSet= SmackProcessLabel=@SMACK_DOMAIN_NAME@ ExecStart=@SYSTEMD_CFG_BIN_DIR@/tef-simulator-daemon -Sockets=tef-simulator.socket RuntimeDirectory=@SERVICE_NAME@ [Install] diff --git a/systemd/tef-simulator.socket b/systemd/tef-simulator.socket index 0551f60..09ecd71 100644 --- a/systemd/tef-simulator.socket +++ b/systemd/tef-simulator.socket @@ -4,11 +4,8 @@ SocketMode=0777 SmackLabelIPIn=* SmackLabelIPOut=@ -Service=tef-simulator.service - [Unit] -Wants=tef-simulator.target -Before=tef-simulator.target +BindsTo=tef-simulator.service [Install] WantedBy=sockets.target diff --git a/systemd/tef-simulator.target b/systemd/tef-simulator.target deleted file mode 100644 index e7be849..0000000 --- a/systemd/tef-simulator.target +++ /dev/null @@ -1,4 +0,0 @@ -[Unit] -Description=TEF Simulator socket -DefaultDependencies=true - -- 2.7.4 From 30cf9f5296119aa0311f1dbee12ed66a658b6b0e Mon Sep 17 00:00:00 2001 From: Tomasz Swierczek Date: Fri, 20 Oct 2017 09:16:01 +0200 Subject: [PATCH 04/16] All TAs should be loaded from sytem TA store. Licence fixes. Client library fixes. Change-Id: Ic106b3c21b22e72f3eaf622cb3d5da6aeb7d827f --- packaging/tef-simulator.spec | 11 ++----- simulatordaemon/src/SecurityContext.cpp | 52 ++++++--------------------------- ssflib/CMakeLists.txt | 1 + systemd/tef-simulator.service.in | 1 + 4 files changed, 14 insertions(+), 51 deletions(-) diff --git a/packaging/tef-simulator.spec b/packaging/tef-simulator.spec index 1f34aef..99f1571 100644 --- a/packaging/tef-simulator.spec +++ b/packaging/tef-simulator.spec @@ -3,7 +3,7 @@ Summary: TEF TrustZone simulator and it's utilities Version: 0.0.1 Release: 1 Group: Security -License: Apache-2.0 and BSD-3-Clause +License: Apache-2.0 Source0: %{name}-%{version}.tar.gz ExcludeArch: armv6l armv7hl armv7l aarch64 BuildRequires: cmake @@ -95,16 +95,12 @@ make install %post ln -sf %{tastore_dir} %{link_tastore_dir} -systemctl enable tef-simulator - -%post -n %{name}-client tef-update.sh simulator +systemctl enable tef-simulator %preun %postun - -%postun -n %{name}-client if [ $1 = 0 ] ; then tef-update.sh fi @@ -115,9 +111,8 @@ fi %attr(770,root,security_fw) %{tastore_dir} %attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.service %attr(444,security_fw,security_fw) %{_unitdir}/tef-simulator.socket +%attr(755,security_fw,security_fw) %{lib_dir}/tef/simulator/libteec.so -%files -n %{name}-client -%attr(111,security_fw,security_fw) %{lib_dir}/tef/simulator/libteec.so %files -n %{name}-devkit %{bin_dir}/TA_PackageBuilder.sh diff --git a/simulatordaemon/src/SecurityContext.cpp b/simulatordaemon/src/SecurityContext.cpp index 5b29ce8..c7d8946 100644 --- a/simulatordaemon/src/SecurityContext.cpp +++ b/simulatordaemon/src/SecurityContext.cpp @@ -111,51 +111,17 @@ std::string SecurityContext::getCaFullPathFromPkgId(char* pkgid) { bool SecurityContext::findRequestedTa(const std::string &ta_name, std::string &allowed_path) { - int ret; - char* pkg_id_ca; - - LOGD(SIM_DAEMON, "Entry"); - ret = security_manager_identify_app_from_socket(connFd, &pkg_id_ca, NULL); - - if (ret == SECURITY_MANAGER_ERROR_NO_SUCH_OBJECT) { - LOGD(SIM_DAEMON, "Owner of socket has no pkgid"); - - std::string ta_full_path; - - /* Check if any of system ta directories contains our ta */ - for (const std::string& path : sysTaPaths) { - ta_full_path = path + ta_name; - - if (fs::exists(ta_full_path)){ - allowed_path = path; - return true; - } + LOGD(SIM_DAEMON, "Entry"); + std::string ta_full_path; + /* Check if any of system ta directories contains our ta */ + for (const std::string& path : sysTaPaths) { + ta_full_path = path + ta_name; + if (fs::exists(ta_full_path)){ + allowed_path = path; + return true; } - - return false; - } - - if (ret != SECURITY_MANAGER_SUCCESS) { - LOGE(SIM_DAEMON, "security_manager_identify_app_from_socket failed with CA"); - return false; - } - - /* We can free it only if security_manager_identify_app_from_socket return success */ - p_char p_pkg_id_ca(pkg_id_ca, &free); - - std::string ca_pkg_path = getCaFullPathFromPkgId(pkg_id_ca); - if (!fs::exists(ca_pkg_path)) { - LOGE(SIM_DAEMON, "Error while loading client's path"); - return false; } - - if (!fs::exists(ca_pkg_path + "/" + ta_name)) { - LOGE(SIM_DAEMON, "TA %s not found in res/tee/", ta_name.c_str()); - return false; - } - - allowed_path = ca_pkg_path + "/"; - return true; + return false; } diff --git a/ssflib/CMakeLists.txt b/ssflib/CMakeLists.txt index 3d456a7..9812d99 100644 --- a/ssflib/CMakeLists.txt +++ b/ssflib/CMakeLists.txt @@ -20,6 +20,7 @@ PKG_CHECK_MODULES(SSFLIB_DEPS REQUIRED openssl tef-libteec + dlog ) SET(SSFLIB_CRYPTOCORE_SOURCES diff --git a/systemd/tef-simulator.service.in b/systemd/tef-simulator.service.in index 85a3efa..a9b767c 100644 --- a/systemd/tef-simulator.service.in +++ b/systemd/tef-simulator.service.in @@ -6,6 +6,7 @@ BindsTo=tef-simulator.socket [Service] User=security_fw Group=security_fw +SupplementaryGroups=users CapabilityBoundingSet= SmackProcessLabel=@SMACK_DOMAIN_NAME@ ExecStart=@SYSTEMD_CFG_BIN_DIR@/tef-simulator-daemon -- 2.7.4 From 32f06f257131d883e84652bd05a5eba01829e7ac Mon Sep 17 00:00:00 2001 From: Jaroslaw Pelczar Date: Fri, 20 Oct 2017 17:44:20 +0200 Subject: [PATCH 05/16] SVACE warnings fixed for HEAP_INCOMPATIBLE.FREE Change-Id: Ib7f2d61d1aaedb48b4f8c0de045d761119f15355 Signed-off-by: Jaroslaw Pelczar --- ssflib/dep/swdss/source/file_op.cpp | 3 ++- ssflib/dep/swdss/source/secure_file.cpp | 9 +++++---- ssflib/dep/swdss/source/ss_temp_store.cpp | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/ssflib/dep/swdss/source/file_op.cpp b/ssflib/dep/swdss/source/file_op.cpp index db18c18..38d135d 100644 --- a/ssflib/dep/swdss/source/file_op.cpp +++ b/ssflib/dep/swdss/source/file_op.cpp @@ -16,6 +16,7 @@ #include "file_op.h" +#include "Osal.h" #include #include #include @@ -116,7 +117,7 @@ int file_op::read_file(const char* filename, unsigned char** buffer, } /* allocating data buffer with enough size */ - *buffer = new uint8_t[size]; + *buffer = (unsigned char *)OsaMalloc(size); if (!(*buffer)) { SLOGD("[%s][%d] Can't malloc pBuffer to 'fread'. ", __FUNCTION__, __LINE__); fclose(file); diff --git a/ssflib/dep/swdss/source/secure_file.cpp b/ssflib/dep/swdss/source/secure_file.cpp index d1cfbda..3fdc18f 100644 --- a/ssflib/dep/swdss/source/secure_file.cpp +++ b/ssflib/dep/swdss/source/secure_file.cpp @@ -20,6 +20,7 @@ #include #include "ss_misc.h" #include "OsaLinuxUser.h" +#include #ifdef _SECOS_SIM_ #include "file_op.h" @@ -129,7 +130,7 @@ static int MDeriveUniqueKey2(const CBT_OCTET* pKeyMaterial, return SS_RET_INTERNAL_ERROR; } - pBuffer = new CBT_OCTET[uKeyMaterialSize + 16]; + pBuffer = new(std::nothrow) CBT_OCTET[uKeyMaterialSize + 16]; if (!pBuffer) { SLOGE("Alloc memory failed.\n"); return SS_RET_MALLOC_FAILED; @@ -1061,7 +1062,7 @@ int secure_file::serialize_data(unsigned char** buffer, __FUNCTION__, __LINE__, FileStructureType(m_file_content.m_pFileHeader)); - delete data; + OsaFree(data); return SS_RET_FAIL; } break; @@ -1082,11 +1083,11 @@ int secure_file::serialize_data(unsigned char** buffer, int secure_file::write_temp_store(unsigned char* data, unsigned int size) { if (-1 == m_cache->write(m_full_path, data, size)) { SLOGI("[%s][%d] Writing to cache storage failed.", __FUNCTION__, __LINE__); - delete data; + OsaFree(data); return SS_RET_FAIL; } - delete data; + OsaFree(data); return SS_RET_SUCCESS; } diff --git a/ssflib/dep/swdss/source/ss_temp_store.cpp b/ssflib/dep/swdss/source/ss_temp_store.cpp index dc272d1..a2d1fde 100644 --- a/ssflib/dep/swdss/source/ss_temp_store.cpp +++ b/ssflib/dep/swdss/source/ss_temp_store.cpp @@ -17,6 +17,7 @@ #include "ss_temp_store.h" #include "slog.h" +#include #define SS_NODE_ID_CMP(id1, id2) memcmp(static_cast(id1),static_cast(id2),SS_NODE_ID_LEN) #define SS_NODE_ID_CPY(dest,src) memcpy(static_cast(dest),static_cast(src),SS_NODE_ID_LEN) @@ -79,7 +80,7 @@ int ss_temp_store::write(char* data_name, unsigned char* data, return SS_RET_SUCCESS; } - node = new temp_ss_node; + node = new(std::nothrow) temp_ss_node; if (NULL == node) { SLOGE("Failed to malloc memory."); return SS_RET_MALLOC_FAILED; @@ -90,7 +91,7 @@ int ss_temp_store::write(char* data_name, unsigned char* data, node->data = (unsigned char*)OsaMalloc(data_size); if (NULL == node->data) { SLOGE("Failed to malloc data."); - OsaFree(node); + delete node; return SS_RET_MALLOC_FAILED; } -- 2.7.4 From 23a2d6030337869f2b00ae2c30d805b0b85cc7d1 Mon Sep 17 00:00:00 2001 From: Jaroslaw Pelczar Date: Fri, 20 Oct 2017 17:53:47 +0200 Subject: [PATCH 06/16] Fix for SVACE DEREF_AFTER_NULL DEREF_AFTER_NULL: After having been compared to NULL value at ssf_crypto.cpp:1990, pointer 'key1' is dereferenced at ssf_crypto.cpp:1999. [dereference] Dereference at /home/abuild/rpmbuild/BUILD/tef- simulator-0.0.1/ssflib/src/ssf_crypto.cpp:1999 [null check] null check at /home/abuild/rpmbuild/BUILD/tef- simulator-0.0.1/ssflib/src/ssf_crypto.cpp:1990 Change-Id: Iaf1ed9dd32b30bc958a91ac1a30382c71b3d4b43 Signed-off-by: Jaroslaw Pelczar --- ssflib/src/ssf_crypto.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/ssflib/src/ssf_crypto.cpp b/ssflib/src/ssf_crypto.cpp index 96f9489..4780887 100644 --- a/ssflib/src/ssf_crypto.cpp +++ b/ssflib/src/ssf_crypto.cpp @@ -1996,15 +1996,20 @@ TEE_Result TEE_SetOperationKey2( TEE_OperationHandle operation, TEE_ObjectHandle return TEE_SUCCESS; } - if ((key1->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) { + if (key1 && (key1->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) { CRYPTO_PANIC; } - if ((key2->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) { + if (key2 && (key2->tr.info.objectUsage | ~op->info.requiredKeyUsage) != 0xffffffff) { CRYPTO_PANIC; } - TEE_CopyObjectAttributes(op->key1, key1); - TEE_CopyObjectAttributes(op->key2, key2); + if(key1) { + TEE_CopyObjectAttributes(op->key1, key1); + } + + if(key2) { + TEE_CopyObjectAttributes(op->key2, key2); + } op->info.handleState |= TEE_HANDLE_FLAG_KEY_SET; return TEE_SUCCESS; -- 2.7.4 From f2e2c6f55af8dadebcc85813fd117e4599bab654 Mon Sep 17 00:00:00 2001 From: Jaroslaw Pelczar Date: Fri, 20 Oct 2017 17:59:20 +0200 Subject: [PATCH 07/16] Fix for SVACE NO_CATCH warning Change-Id: I6950fab634aa6c6f2c448aaa7cfc0c3a1978c464 Signed-off-by: Jaroslaw Pelczar --- TEEStub/teestubmain.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/TEEStub/teestubmain.cpp b/TEEStub/teestubmain.cpp index d62e74a..0ffdb15 100644 --- a/TEEStub/teestubmain.cpp +++ b/TEEStub/teestubmain.cpp @@ -54,6 +54,8 @@ void StartServer(string socketName) { io_service.run(); } catch (std::exception& e) { LOGE(TEE_STUB, "Exception: %s", e.what()); + } catch (...) { + LOGE(TEE_STUB, "Unknown exception"); } } -- 2.7.4 From 43c72359c928ca41862809d1c2942220ea492a62 Mon Sep 17 00:00:00 2001 From: Igor Kotrasinski Date: Mon, 23 Oct 2017 09:55:27 +0200 Subject: [PATCH 08/16] SVACE: HEAP_LEAK, correct size in strncpy Change-Id: Ib53c48c7f6ab9aaa1e00ea407bbcad329aa38a3a --- ssflib/dep/cryptocore/source/base/cc_bignum.c | 1 + ssflib/dep/swdss/source/file_op.cpp | 8 ++------ ssflib/dep/swdss/source/secure_file.cpp | 26 +++++++++++++++----------- ssflib/dep/swdss/source/ss_api.cpp | 6 ++---- ssflib/src/ssf_storage.cpp | 5 ++--- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/ssflib/dep/cryptocore/source/base/cc_bignum.c b/ssflib/dep/cryptocore/source/base/cc_bignum.c index b1561ab..5dc6043 100644 --- a/ssflib/dep/cryptocore/source/base/cc_bignum.c +++ b/ssflib/dep/cryptocore/source/base/cc_bignum.c @@ -3107,6 +3107,7 @@ cc_u8 * SDRM_BN2STRFOUR(cc_u32 *numberBits, SDRM_BIG_NUM *BN_Src) num = SDRM_BN_Init(BN_Src->Size); if( num == NULL)//fix prevent cid = 89093 by guoxing.xu { + free(num); free(strDestTemp); SDRM_BN_FREE(d); return NULL; diff --git a/ssflib/dep/swdss/source/file_op.cpp b/ssflib/dep/swdss/source/file_op.cpp index 38d135d..eafe680 100644 --- a/ssflib/dep/swdss/source/file_op.cpp +++ b/ssflib/dep/swdss/source/file_op.cpp @@ -230,14 +230,10 @@ bool file_op::is_file_exists(const char* file) { } void file_op::get_base_path(const char* filename, char* base_path) { - char tmp[256] = {0}; - memcpy(tmp, filename, strlen(filename)); - for (int i = strlen(filename) - 1; i >= 0; --i) { - tmp[i] = 0; - if ('/' == filename[i]) { - memcpy(base_path, tmp, strlen(tmp)); + memcpy(base_path, filename, i); + base_path[i] = '\0'; break; } } diff --git a/ssflib/dep/swdss/source/secure_file.cpp b/ssflib/dep/swdss/source/secure_file.cpp index 3fdc18f..9a828f1 100644 --- a/ssflib/dep/swdss/source/secure_file.cpp +++ b/ssflib/dep/swdss/source/secure_file.cpp @@ -29,6 +29,8 @@ #endif +#define MAX_FILENAME_LEN 256 + // this is RNG SEED for mask static const CBT_UINT32 RNG_SEED = 0xa3e59cf2; // this is RNG SEED for mask @@ -383,9 +385,8 @@ int secure_file::initialize(const ss_credential_s * cred, const char* data_name, m_data_name[0] = '\0'; if (NULL != data_name) { - int data_name_len = strlen(data_name); - memcpy(m_data_name, data_name, data_name_len); - m_data_name[data_name_len] = '\0'; + strncpy(m_data_name, data_name, sizeof(m_data_name)); + m_data_name[sizeof(m_data_name)-1] = '\0'; } m_options = options; @@ -942,7 +943,7 @@ int secure_file::serialize_data(unsigned char** buffer, unsigned int& ret_size) { #ifdef _SECOS_SIM_ *buffer = (unsigned char*)OsaMalloc(m_write_data_size); - if (NULL == buffer) { + if (NULL == *buffer) { //SLOGE("fail to alloc memory for data."); return SS_RET_MALLOC_FAILED; } @@ -1094,7 +1095,7 @@ int secure_file::write_temp_store(unsigned char* data, unsigned int size) { int secure_file::write_persistent_store(unsigned char* data, unsigned int size) { #ifdef _SECOS_SIM_ - char filename[256] = {0}; + char filename[MAX_FILENAME_LEN] = {0}; get_data_name(filename, false); int iRet = file_op::write_file(filename, data, size); OsaFree(data); @@ -1144,7 +1145,7 @@ int secure_file::read_temp_store(unsigned char** buffer, int secure_file::read_persistent_store(unsigned char** buffer, unsigned int& ret_size) { #ifdef _SECOS_SIM_ - char filename[256] = {0}; + char filename[MAX_FILENAME_LEN] = {0}; get_data_name(filename, false); return file_op::read_file(filename, buffer, ret_size); #else @@ -1191,7 +1192,7 @@ int secure_file::read_persistent_store(unsigned char** buffer, int secure_file::remove_persistent_store(bool is_dir) { #ifdef _SECOS_SIM_ - char filename[256] = {0}; + char filename[MAX_FILENAME_LEN] = {0}; get_data_name(filename, is_dir); int iret = SS_RET_SUCCESS; if (is_dir) { @@ -1447,6 +1448,7 @@ int secure_file::write(unsigned char* buffer, unsigned int buf_size, unsigned char* data = NULL; unsigned int size = 0; if (SS_RET_SUCCESS != (ret = serialize_data(&data, size))) { + free(data); return ret; } @@ -1722,20 +1724,22 @@ int secure_file::clear_storage() { #ifdef _SECOS_SIM_ #define SS_CRED_LEN 36 void secure_file::get_data_name(char* data_name, bool is_dir) { - uint8_t* ptr = (uint8_t*)data_name; - memcpy(ptr, SWD_SS_ROOT, strlen(SWD_SS_ROOT)); + char* ptr = data_name; + strncpy(ptr, SWD_SS_ROOT, MAX_FILENAME_LEN - (ptr-data_name)); ptr += strlen(SWD_SS_ROOT); // first 4 bytes for directory. //byte_to_hex(ptr, (uint8_t*)m_full_path, 4); - memcpy(ptr, m_full_path, SS_CRED_LEN); + strncpy(ptr, m_full_path, SS_CRED_LEN); + ptr[SS_CRED_LEN] = '\0'; if (is_dir) { return; } // next 8 bytes for filename - memcpy(ptr, m_full_path, strlen(m_full_path)); + strncpy(ptr, m_full_path, MAX_FILENAME_LEN - (ptr-data_name)); + data_name[MAX_FILENAME_LEN - 1] = '\0'; //memset(ptr, '/', 1); //ptr += 1; //memcpy(ptr,m_full_path+SS_CRED_LEN,) diff --git a/ssflib/dep/swdss/source/ss_api.cpp b/ssflib/dep/swdss/source/ss_api.cpp index 5619d11..b6ada9f 100644 --- a/ssflib/dep/swdss/source/ss_api.cpp +++ b/ssflib/dep/swdss/source/ss_api.cpp @@ -34,16 +34,14 @@ int ss_set_credential(ss_credential_s * cred, const char* uuid, return SS_RET_INVALID_PARAM; } - int uuid_size = strlen(uuid); - int mn_size = strlen(module_name); + int uuid_size = strnlen(uuid, SS_MAX_UUID_LEN) + 1; + int mn_size = strnlen(module_name, SS_MAX_MODULE_NAME_LEN) + 1; if (uuid_size > SS_MAX_UUID_LEN || mn_size > SS_MAX_MODULE_NAME_LEN) { SLOGE("[%s] length of uuid or module name error.\n", __FUNCTION__); return SS_RET_INVALID_PARAM; } - memset(cred->uuid, '\0', SS_MAX_UUID_LEN); - memset(cred->module_name, '\0', SS_MAX_MODULE_NAME_LEN); strncpy(cred->uuid, uuid, uuid_size); strncpy(cred->module_name, module_name, mn_size); diff --git a/ssflib/src/ssf_storage.cpp b/ssflib/src/ssf_storage.cpp index 33a494e..cfe01da 100644 --- a/ssflib/src/ssf_storage.cpp +++ b/ssflib/src/ssf_storage.cpp @@ -790,9 +790,8 @@ int init_po_info_file(po_info_file* pi_file) { char uuid[64] = {0}; convert_TA_UUID(uuid, tmp_uuid); ss_set_credential(&pi_file->cred, uuid, PO_INTERNAL_MODULE_NAME, 1, 0); - uint32_t fn_sz = strlen(PI_FILE_NAME); - memcpy(pi_file->filename, PI_FILE_NAME, fn_sz); - pi_file->filename[fn_sz] = '\0'; + strncpy(pi_file->filename, PI_FILE_NAME, sizeof(pi_file->filename)); + pi_file->filename[sizeof(pi_file->filename)-1] = '\0'; pi_file->b_inited = 1; return 0; } -- 2.7.4 From 655119962b0100380bfb4a005d89814f26e9afa6 Mon Sep 17 00:00:00 2001 From: Krzysztof Dynowski Date: Mon, 23 Oct 2017 17:41:12 +0200 Subject: [PATCH 09/16] SVACE: fix UNINIT.CTOR Change-Id: I4029146e8b408e931b0555bd7e9ac8d61722741f --- TEEStub/PropertyAccess/Property.h | 2 +- TEEStub/PropertyAccess/rapidxml/rapidxml.hpp | 7 ++++--- TEEStub/TEEStubServer/ConnectionSession.h | 2 +- simulatordaemon/inc/ConnectionSession.h | 2 +- simulatordaemon/src/TABinaryManager/rapidxml/rapidxml.hpp | 7 ++++--- simulatordaemon/src/TAInstance.cpp | 4 +++- ssflib/dep/cryptocore/source/base/cc_bignum.c | 7 +++---- 7 files changed, 17 insertions(+), 14 deletions(-) diff --git a/TEEStub/PropertyAccess/Property.h b/TEEStub/PropertyAccess/Property.h index f7413ea..80ecb4c 100644 --- a/TEEStub/PropertyAccess/Property.h +++ b/TEEStub/PropertyAccess/Property.h @@ -54,7 +54,7 @@ public: void setPropSet(uintptr_t propset) { this->propset = propset; }; - Property() { + Property() : propset(0) { } ; virtual ~Property() { diff --git a/TEEStub/PropertyAccess/rapidxml/rapidxml.hpp b/TEEStub/PropertyAccess/rapidxml/rapidxml.hpp index 73a2b78..f1aa61e 100644 --- a/TEEStub/PropertyAccess/rapidxml/rapidxml.hpp +++ b/TEEStub/PropertyAccess/rapidxml/rapidxml.hpp @@ -617,7 +617,7 @@ public: // Construct a base with empty name, value and parent xml_base() : - m_name(0), m_value(0), m_parent(0) { + m_name(0), m_value(0), m_name_size(0), m_value_size(0), m_parent(0) { } /////////////////////////////////////////////////////////////////////////// @@ -756,7 +756,7 @@ public: //! Constructs an empty attribute with the specified type. //! Consider using memory_pool of appropriate xml_document if allocating attributes manually. - xml_attribute() { + xml_attribute() : m_prev_attribute(0), m_next_attribute(0) { } /////////////////////////////////////////////////////////////////////////// @@ -839,7 +839,8 @@ public: //! Consider using memory_pool of appropriate document to allocate nodes manually. //! \param type Type of node to construct. xml_node(node_type type) : - m_type(type), m_first_node(0), m_first_attribute(0) { + m_type(type), m_first_node(0), m_last_node(0), m_first_attribute(0), m_last_attribute(0), + m_prev_sibling(0), m_next_sibling(0) { } /////////////////////////////////////////////////////////////////////////// diff --git a/TEEStub/TEEStubServer/ConnectionSession.h b/TEEStub/TEEStubServer/ConnectionSession.h index 08df68c..0d7b453 100644 --- a/TEEStub/TEEStubServer/ConnectionSession.h +++ b/TEEStub/TEEStubServer/ConnectionSession.h @@ -52,7 +52,7 @@ class ConnectionSession: public boost::enable_shared_from_thispData = (cc_u32*)(void*)(pbBuf + sizeof(SDRM_BIG_NUM)); + BN_Src->pData = (cc_u32*)(void*)((char*)BN_Src + sizeof(SDRM_BIG_NUM)); BN_Src->Size = dSize; return BN_Src; @@ -3107,8 +3106,8 @@ cc_u8 * SDRM_BN2STRFOUR(cc_u32 *numberBits, SDRM_BIG_NUM *BN_Src) num = SDRM_BN_Init(BN_Src->Size); if( num == NULL)//fix prevent cid = 89093 by guoxing.xu { - free(num); free(strDestTemp); + SDRM_BN_FREE(tempREM); SDRM_BN_FREE(d); return NULL; } -- 2.7.4 From b63e5a7c5062a7754819cbc65a4a9092f265b4ad Mon Sep 17 00:00:00 2001 From: Leszek Zygo Date: Mon, 23 Oct 2017 17:55:49 +0200 Subject: [PATCH 10/16] Fix C++ style warnings (CRC) Change-Id: Ief75cb7fb549697ddab8cec0c5ebd41c9c1149d8 Signed-off-by: Leszek Zygo --- TEEStub/PropertyAccess/PropertyApi.cpp | 52 +- TEEStub/PropertyAccess/PropertyUtility.cpp | 14 +- TEEStub/PropertyAccess/TAProperty.cpp | 14 +- TEEStub/PropertyAccess/TEEProperty.cpp | 9 +- TEEStub/TACommands/MakeCommand.cpp | 3 - TEEStub/TACommands/SharedMemoryMap.cpp | 7 +- TEEStub/TEEStubServer/ConnectionSession.cpp | 8 +- TEEStub/TaskStrategy/TaskQueuedStrategy.cpp | 6 +- TEEStub/teestubmain.cpp | 1 - include/include/tee_internal_api.h | 3 +- include/include/tee_sim_command.h | 1 - include/include/teestub_command_data.h | 1 - log/log.h | 26 +- osal/Osal.h | 10 +- simulatordaemon/inc/ClientCommands/CommandBase.h | 1 - .../inc/ClientCommands/CommandInvokeCommand.h | 1 - .../inc/ClientCommands/CommandInvokeTACommand.h | 1 - simulatordaemon/inc/ClientCommands/CommandPanic.h | 1 - .../inc/ClientCommands/CommandRegSharedMem.h | 1 - .../inc/ClientCommands/CommandRelSharedMem.h | 1 - .../inc/ClientCommands/CommandReqCancellation.h | 1 - .../inc/ResponseCommands/ResCommandInvokeCommand.h | 1 - .../ResponseCommands/ResCommandReqCancellation.h | 1 - .../src/ClientCommands/CommandCloseSession.cpp | 1 - .../src/ClientCommands/CommandCloseTASession.cpp | 1 - .../src/ClientCommands/CommandInvokeCommand.cpp | 1 - .../src/ClientCommands/CommandInvokeTACommand.cpp | 1 - .../src/ClientCommands/CommandOpenTASession.cpp | 1 - simulatordaemon/src/ClientCommands/MakeCommand.cpp | 2 - simulatordaemon/src/ConnectionSession.cpp | 17 +- .../ResponseCommands/ResCommandCloseSession.cpp | 5 +- .../ResponseCommands/ResCommandInvokeCommand.cpp | 1 - .../src/ResponseCommands/ResMakeCommand.cpp | 2 - simulatordaemon/src/SecurityContext.cpp | 1 - simulatordaemon/src/Session.cpp | 6 +- .../src/TABinaryManager/TABinaryManager.h | 1 - simulatordaemon/src/TABinaryManager/TAManifest.cpp | 8 +- simulatordaemon/src/TABinaryManager/TAManifest.h | 2 - simulatordaemon/src/TABinaryManager/TAUnpack.cpp | 3 - simulatordaemon/src/TABinaryManager/TestMain.cpp | 2 - simulatordaemon/src/TAFactory.cpp | 10 +- simulatordaemon/src/TAInstance.cpp | 27 +- simulatordaemon/src/TEEContext.cpp | 11 - ssflib/dep/cryptocore/include/CC_API.h | 55 ++- ssflib/dep/cryptocore/include/CC_Context.h | 3 +- ssflib/dep/cryptocore/include/base/cc_bignum.h | 22 +- ssflib/dep/cryptocore/include/base/cc_des.h | 290 ++++++------ ssflib/dep/cryptocore/include/base/cc_ecc.h | 8 +- ssflib/dep/cryptocore/include/base/cc_fast_math.h | 6 +- ssflib/dep/cryptocore/include/base/cc_md5.h | 4 +- ssflib/dep/cryptocore/include/base/cc_moo.h | 2 +- ssflib/dep/cryptocore/include/drm_macro.h | 54 +-- ssflib/dep/swdss/include/file_op.h | 1 - ssflib/dep/swdss/include/secure_file.h | 1 - ssflib/dep/swdss/include/ss_types.h | 1 - ssflib/dep/swdss/source/file_op.cpp | 2 +- ssflib/dep/swdss/source/ss_crypto.cpp | 40 +- ssflib/dep/swdss/source/ss_temp_store.cpp | 5 +- ssflib/dep/time/ssf_time.cpp | 3 +- ssflib/dep/uci/include/uci_type.h | 5 - ssflib/inc/app_debug.h | 26 +- ssflib/inc/permission.h | 10 +- ssflib/src/app_debug.cpp | 27 +- ssflib/src/ssf_arithmetic.cpp | 5 +- ssflib/src/ssf_crypto.cpp | 523 +++++++++------------ ssflib/src/ssf_lib.cpp | 1 - ssflib/src/ssf_storage.cpp | 8 +- ssflib/src/ssf_taentrypoint.cpp | 5 +- 68 files changed, 613 insertions(+), 761 deletions(-) diff --git a/TEEStub/PropertyAccess/PropertyApi.cpp b/TEEStub/PropertyAccess/PropertyApi.cpp index 93c67ba..60f1199 100644 --- a/TEEStub/PropertyAccess/PropertyApi.cpp +++ b/TEEStub/PropertyAccess/PropertyApi.cpp @@ -142,7 +142,8 @@ TEE_Result TEE_GetPropertyAsString(TEE_PropSetHandle propsetOrEnumerator, if (valueBuffer && pv.value.size() < *valueBufferLen) strncpy(valueBuffer, pv.value.c_str(), *valueBufferLen); else returnValue = TEE_ERROR_SHORT_BUFFER; - } else returnValue = TEE_ERROR_ITEM_NOT_FOUND; + } + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; // Above is optimized version of below #if 0 @@ -154,16 +155,13 @@ TEE_Result TEE_GetPropertyAsString(TEE_PropSetHandle propsetOrEnumerator, strcpy(valueBuffer, pv.value.c_str()); else returnValue = TEE_ERROR_SHORT_BUFFER; - } - else if (NULL == name && targetProperty && targetProperty->getPropertyValue(pv)) - { + } else if (NULL == name && targetProperty && targetProperty->getPropertyValue(pv)) { if (pv.value.size() < *valueBufferLen) strcpy(valueBuffer, pv.value.c_str()); else returnValue = TEE_ERROR_SHORT_BUFFER; } - else - returnValue = TEE_ERROR_ITEM_NOT_FOUND; + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; #endif return returnValue; } @@ -184,19 +182,17 @@ TEE_Result TEE_GetPropertyAsBool(TEE_PropSetHandle propsetOrEnumerator, && ((NULL != name && targetProperty->getPropertyByName(queryProp, pv)) || (NULL == name && targetProperty->getPropertyValue(pv)))) { returnValue = PropertyUtility::convertToBool(pv, *value); - } else returnValue = TEE_ERROR_ITEM_NOT_FOUND; + } + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; // Above is optimized version of below #if 0 if (NULL != name && targetProperty && targetProperty->getPropertyByName(queryProp, pv)) { returnValue = PropertyUtility::convertToBool(pv, *value); - } - else if (NULL == name && targetProperty && targetProperty->getPropertyValue(pv)) - { + } else if (NULL == name && targetProperty && targetProperty->getPropertyValue(pv)) { returnValue = PropertyUtility::convertToBool(pv, *value); } - else - returnValue = TEE_ERROR_ITEM_NOT_FOUND; + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; #endif return returnValue; } @@ -207,7 +203,7 @@ TEE_Result TEE_GetPropertyAsU32(TEE_PropSetHandle propsetOrEnumerator, Property* targetProperty = NULL; PropertyValue pv; string queryProp = ""; - if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator,name); + if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator, name); // 1. Select the enumerator object based on propset or consider given enumerator // if any targetProperty = _GetTargetProperty(propsetOrEnumerator); @@ -217,7 +213,8 @@ TEE_Result TEE_GetPropertyAsU32(TEE_PropSetHandle propsetOrEnumerator, && ((NULL != name && targetProperty->getPropertyByName(queryProp, pv)) || (NULL == name && targetProperty->getPropertyValue(pv)))) { returnValue = PropertyUtility::convertToU32(pv, *value); - } else returnValue = TEE_ERROR_ITEM_NOT_FOUND; + } + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; return returnValue; } @@ -227,7 +224,7 @@ TEE_Result TEE_GetPropertyAsBinaryBlock(TEE_PropSetHandle propsetOrEnumerator, Property* targetProperty = NULL; PropertyValue pv; string queryProp = ""; - if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator,name); + if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator, name); // Select the enumerator object based on propset or consider given enumerator // if any targetProperty = _GetTargetProperty(propsetOrEnumerator); @@ -241,8 +238,10 @@ TEE_Result TEE_GetPropertyAsBinaryBlock(TEE_PropSetHandle propsetOrEnumerator, if (valueBuffer && conversionStatus && binaryBlockOut.size() < *valueBufferLen) { strncpy((char*)valueBuffer, binaryBlockOut.c_str(), *valueBufferLen); - } else returnValue = TEE_ERROR_SHORT_BUFFER; - } else returnValue = TEE_ERROR_ITEM_NOT_FOUND; + } + else returnValue = TEE_ERROR_SHORT_BUFFER; + } + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; return returnValue; } @@ -254,7 +253,7 @@ TEE_Result TEE_GetPropertyAsUUID(TEE_PropSetHandle propsetOrEnumerator, Property* targetProperty = NULL; PropertyValue pv; string queryProp = ""; - if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator,name); + if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator, name); // 1. Select the enumerator object based on propset or consider given enumerator // if any targetProperty = _GetTargetProperty(propsetOrEnumerator); @@ -264,7 +263,8 @@ TEE_Result TEE_GetPropertyAsUUID(TEE_PropSetHandle propsetOrEnumerator, && ((NULL != name && targetProperty->getPropertyByName(queryProp, pv)) || (NULL == name && targetProperty->getPropertyValue(pv)))) { returnValue = PropertyUtility::convertToUUID(pv, *value); - } else returnValue = TEE_ERROR_ITEM_NOT_FOUND; + } + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; return returnValue; } @@ -276,7 +276,7 @@ TEE_Result TEE_GetPropertyAsIdentity(TEE_PropSetHandle propsetOrEnumerator, Property* targetProperty = NULL; PropertyValue pv; string queryProp = ""; - if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator,name); + if (NULL != name) queryProp = getQueryProp(propsetOrEnumerator, name); // 1. Select the enumerator object based on propset or consider given enumerator // if any targetProperty = _GetTargetProperty(propsetOrEnumerator); @@ -286,7 +286,8 @@ TEE_Result TEE_GetPropertyAsIdentity(TEE_PropSetHandle propsetOrEnumerator, && ((NULL != name && targetProperty->getPropertyByName(queryProp, pv)) || (NULL == name && targetProperty->getPropertyValue(pv)))) { returnValue = PropertyUtility::convertToIdentity(pv, *value); - } else returnValue = TEE_ERROR_ITEM_NOT_FOUND; + } + else returnValue = TEE_ERROR_ITEM_NOT_FOUND; return returnValue; } @@ -311,8 +312,7 @@ void TEE_FreePropertyEnumerator(TEE_PropSetHandle enumerator) { propertyEnumHandleSet.erase(it); delete enumeratorHandle->property; delete enumeratorHandle; - } - else { + } else { TEE_Panic(0); } } @@ -382,7 +382,8 @@ TEE_Result TEE_GetPropertyName(TEE_PropSetHandle enumerator, void* nameBuffer, } // item not found or enumerator end has reached else return TEE_ERROR_ITEM_NOT_FOUND; - } else return TEE_ERROR_ITEM_NOT_FOUND; + } + else return TEE_ERROR_ITEM_NOT_FOUND; return TEE_SUCCESS; } @@ -392,7 +393,8 @@ TEE_Result TEE_GetNextProperty(TEE_PropSetHandle enumerator) { if (enumeratorHandle && enumeratorHandle->property && enumeratorHandle->property->getNextProperty()) { return TEE_SUCCESS; - } else return TEE_ERROR_ITEM_NOT_FOUND; + } + else return TEE_ERROR_ITEM_NOT_FOUND; } uintptr_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator) { diff --git a/TEEStub/PropertyAccess/PropertyUtility.cpp b/TEEStub/PropertyAccess/PropertyUtility.cpp index 0b776c5..930f5d3 100644 --- a/TEEStub/PropertyAccess/PropertyUtility.cpp +++ b/TEEStub/PropertyAccess/PropertyUtility.cpp @@ -90,13 +90,9 @@ TEE_Result PropertyUtility::convertToU32(const PropertyValue& in, if (in.type == "integer") { sstr << in.value; sstr >> out; - } - else if (in.type == "boolean") - { + } else if (in.type == "boolean") { out = (in.value == "true" ? 1 : 0); - } - else - { // As per spec:A pointer to the variable that will contain the value of the property + } else {// As per spec:A pointer to the variable that will contain the value of the property // on success, or zero on error // Hence default value is "false" out = 0; @@ -149,7 +145,8 @@ TEE_Result PropertyUtility::convertToUUID(const PropertyValue& in, uuid.clockSeqAndNode[6] = temp[1]; uuid.clockSeqAndNode[7] = temp[0]; out = uuid; - } else returnValue = TEE_ERROR_BAD_FORMAT; + } + else returnValue = TEE_ERROR_BAD_FORMAT; return returnValue; } @@ -165,7 +162,8 @@ TEE_Result PropertyUtility::convertToIdentity(const PropertyValue& in, TEE_Identity& out) { if ("identity" != in.type) return TEE_ERROR_BAD_FORMAT; - else { + else + { out.login = atoi(in.value.c_str()); // Set to Nil UUID as per [RFC 4122]. out.uuid.timeLow = 0; diff --git a/TEEStub/PropertyAccess/TAProperty.cpp b/TEEStub/PropertyAccess/TAProperty.cpp index 41a970e..8cefc10 100644 --- a/TEEStub/PropertyAccess/TAProperty.cpp +++ b/TEEStub/PropertyAccess/TAProperty.cpp @@ -80,11 +80,13 @@ bool TAProperty::readPropertyFile() { // TODO: UUID type to be added yet if (PropertyUtility::isNumber(newValue.value)) { type = "integer"; - } else if (newValue.value == "true" || newValue.value == "false") + } else if (newValue.value == "true" || newValue.value == "false") { type = "boolean"; - else if (typeName == "appID") + } else if (typeName == "appID") { type = "uuid"; - else type = "string"; + } else { + type = "string"; + } //1c. Assign type identified newValue.type = type; @@ -199,7 +201,8 @@ bool TAProperty::getPropertyValue(PropertyValue &pv) { if (currentItr != propertiesMap.end()) { pv = currentItr->second; return true; - } else return false; + } + else return false; } /** @@ -220,6 +223,7 @@ bool TAProperty::getPropertyByName(const string &propName, map::iterator it = propertiesMap.find(propName); if (it != propertiesMap.end()) { value = it->second; - } else returnval = false; + } + else returnval = false; return returnval; } diff --git a/TEEStub/PropertyAccess/TEEProperty.cpp b/TEEStub/PropertyAccess/TEEProperty.cpp index 0ce5dc7..de47826 100644 --- a/TEEStub/PropertyAccess/TEEProperty.cpp +++ b/TEEStub/PropertyAccess/TEEProperty.cpp @@ -50,7 +50,6 @@ TEEProperty::TEEProperty() { * @return true if successfully read else false */ bool TEEProperty::readPropertyFile(string filePath) { - // Open file std::ifstream xmlfile(filePath.c_str()); if (xmlfile.fail()) return false; @@ -138,7 +137,9 @@ bool TEEProperty::getPropertyValue(PropertyValue &pv) { if (currentItr != propertiesMap.end()) { pv = currentItr->second; return true; - } else return false; + } else { + return false; + } } /** @@ -159,6 +160,8 @@ bool TEEProperty::getPropertyByName(const string &propName, map::iterator it = propertiesMap.find(propName); if (it != propertiesMap.end()) { value = it->second; - } else returnval = false; + } else { + returnval = false; + } return returnval; } diff --git a/TEEStub/TACommands/MakeCommand.cpp b/TEEStub/TACommands/MakeCommand.cpp index 8820936..e36348b 100644 --- a/TEEStub/TACommands/MakeCommand.cpp +++ b/TEEStub/TACommands/MakeCommand.cpp @@ -35,7 +35,6 @@ * @param data pointer to structure defining the command in SIM_COMMAND */ CommandBasePtr MakeCommand::getCommand(SIM_COMMAND simcommand, void* simdata) { - CommandBasePtr command; switch (simcommand) { case CREATE: { @@ -83,7 +82,6 @@ CommandBasePtr MakeCommand::getCommand(SIM_COMMAND simcommand, void* simdata) { } MakeCommand::~MakeCommand() { - } /** @@ -95,7 +93,6 @@ MakeCommand::~MakeCommand() { * */ int MakeCommand::getCommandPayloadSize(SIM_COMMAND command) { - int size = -1; switch (command) { case CREATE: diff --git a/TEEStub/TACommands/SharedMemoryMap.cpp b/TEEStub/TACommands/SharedMemoryMap.cpp index 0c299b3..44e5ac4 100644 --- a/TEEStub/TACommands/SharedMemoryMap.cpp +++ b/TEEStub/TACommands/SharedMemoryMap.cpp @@ -180,8 +180,7 @@ bool SharedMemoryMap::deleteOnceSharedMemory(void* buffer) { for (map::iterator it = shmMap.begin(); it != shmMap.end(); it++) { registerItem item = it->second; - if(buffer == item.pBuffer) { - + if (buffer == item.pBuffer) { if (!item.internal) { return false; } @@ -230,9 +229,7 @@ bool SharedMemoryMap::allocateSharedMemory(Operation &op) { { op.params[i].memref.buffer = (void*)((char*)item.pBuffer + offset); - } - else - { + } else { std::string shm_name(SHM_NAME_PREFIX + std::to_string(op.shmID[i])); int fd_shm = shm_open(shm_name.c_str(), O_RDWR, 0); diff --git a/TEEStub/TEEStubServer/ConnectionSession.cpp b/TEEStub/TEEStubServer/ConnectionSession.cpp index c970b8c..821898f 100644 --- a/TEEStub/TEEStubServer/ConnectionSession.cpp +++ b/TEEStub/TEEStubServer/ConnectionSession.cpp @@ -78,7 +78,7 @@ void ConnectionSession::handleRead(const boost::system::error_code& error, case READ_PAYLOAD: { // Identify command command = (SIM_COMMAND)clientData.at(0); - LOGD(TEE_STUB, "Command received: %d", (int )command); + LOGD(TEE_STUB, "Command received: %d", (int)command); // Calculate pending numbers of bytes pending to be read only for commands // OPENSESSION, INVOKECOMMAND, CLOSESESSION @@ -92,8 +92,7 @@ void ConnectionSession::handleRead(const boost::system::error_code& error, boost::bind(&ConnectionSession::handleRead, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - } - else if (-1 == payload_size) { + } else if (-1 == payload_size) { // else case is invalid command // TODO: Identify the correct behaviour; what to do when invalid command is received? LOGE(TEE_STUB, "Invalid command received!"); @@ -138,9 +137,8 @@ void ConnectionSession::handleRead(const boost::system::error_code& error, break; } //case } //switch - } + } else { // On error - else { LOGE(TEE_STUB, "error code %s", error.category().name()); if (boost::asio::error::eof == error.value()) { LOGE(TEE_STUB, "Simulator daemon is down! Exiting this TA instance."); diff --git a/TEEStub/TaskStrategy/TaskQueuedStrategy.cpp b/TEEStub/TaskStrategy/TaskQueuedStrategy.cpp index b878ce0..11d23bd 100644 --- a/TEEStub/TaskStrategy/TaskQueuedStrategy.cpp +++ b/TEEStub/TaskStrategy/TaskQueuedStrategy.cpp @@ -62,9 +62,8 @@ void TaskQueuedStrategy::handleCommand(CommandBasePtr command) { ss.addTask(command); sessionTaskMap[command->sessionID] = ss; LOGD(TEE_STUB, "New Session ID"); - } + } else { // Else, the session ID exists in map, so append to list in session - else { LOGD(TEE_STUB, "Session ID Exists, adding tasks"); sessionTaskMap[command->sessionID].addTask(command); } @@ -92,12 +91,11 @@ void TaskQueuedStrategy::executeCancellation(CommandBasePtr cancelCommand) { if (currentCommand->getCommandUID() == cancelCommand->getCommandUID()) { LOGD(TEE_STUB, "Cancel command matched with current task"); sharedData.thisTaskCancel = true; - } + } else { // If the task to be cancelled is not the current task // then the task must be in execution queue, yet to be executed. // Just push the request to cancellation vector using // cancel commands execute - else { LOGD(TEE_STUB, "Cancel command queued"); cancelCommand->execute(); } diff --git a/TEEStub/teestubmain.cpp b/TEEStub/teestubmain.cpp index 0ffdb15..2f1f604 100644 --- a/TEEStub/teestubmain.cpp +++ b/TEEStub/teestubmain.cpp @@ -74,7 +74,6 @@ void StopServer() { * @return */ int main(int argc, char* argv[]) { - if (argc < 2) { LOGE(TEE_STUB, "Invalid arguments to TEE Stub"); } diff --git a/include/include/tee_internal_api.h b/include/include/tee_internal_api.h index b988af0..9456e2e 100644 --- a/include/include/tee_internal_api.h +++ b/include/include/tee_internal_api.h @@ -94,7 +94,6 @@ typedef enum { TEE_ERROR_CERT_VERIFICATION = 0xFFFF6003, TEE_RESULT_NOT_READY = 0xFFFF0FFF - } TEE_Error_Codes; #define TEE_HANDLE_NULL 0 @@ -122,7 +121,7 @@ typedef union { } value; } TEE_Param; -#define TEE_PARAM_TYPES(t0,t1,t2,t3) \ +#define TEE_PARAM_TYPES(t0, t1, t2, t3) \ ((t0) | ((t1) << 8) | ((t2) << 16) | ((t3) << 24)) #define TEE_PARAM_TYPE_GET(t, i) (((t) >> (i*8)) & 0x7F) diff --git a/include/include/tee_sim_command.h b/include/include/tee_sim_command.h index d49d1f9..dcb4c24 100644 --- a/include/include/tee_sim_command.h +++ b/include/include/tee_sim_command.h @@ -76,7 +76,6 @@ typedef struct { uint32_t operationID; TEE_Result returnValue; uint32_t returnOrigin; - } RequestTACancelData; #endif /* __TEE_SIM_COMMAND_H__ */ diff --git a/include/include/teestub_command_data.h b/include/include/teestub_command_data.h index 12f8b0d..5d361cb 100644 --- a/include/include/teestub_command_data.h +++ b/include/include/teestub_command_data.h @@ -55,7 +55,6 @@ typedef struct { typedef struct { uint32_t session; - } IntTACloseSessionData; typedef struct { diff --git a/log/log.h b/log/log.h index eea9bd8..11b2fd4 100644 --- a/log/log.h +++ b/log/log.h @@ -104,23 +104,23 @@ typedef enum { #ifdef _LOGGING -#define _LOG(module_level,debug_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,debug_level,##__VA_ARGS__) +#define _LOG(module_level, debug_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, debug_level, ##__VA_ARGS__) -#define LOGE(module_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,ERROR_LEVEL_LOG,##__VA_ARGS__) -#define LOGV(module_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,VERBOSE_LEVEL_LOG,##__VA_ARGS__) -#define LOGD(module_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,DEBUG_LEVEL_LOG,##__VA_ARGS__) -#define LOGI(module_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,SECURED_LEVEL_LOG,##__VA_ARGS__) -#define LOGS(module_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,INFO_LEVEL_LOG,##__VA_ARGS__) -#define LOGP(module_level,...) PrintLog(__FUNCTION__,__LINE__,module_level,PACKET_LEVEL_LOG,##__VA_ARGS__) +#define LOGE(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, ERROR_LEVEL_LOG, ##__VA_ARGS__) +#define LOGV(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, VERBOSE_LEVEL_LOG, ##__VA_ARGS__) +#define LOGD(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, DEBUG_LEVEL_LOG, ##__VA_ARGS__) +#define LOGI(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, SECURED_LEVEL_LOG, ##__VA_ARGS__) +#define LOGS(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, INFO_LEVEL_LOG, ##__VA_ARGS__) +#define LOGP(module_level, ...) PrintLog(__FUNCTION__, __LINE__, module_level, PACKET_LEVEL_LOG, ##__VA_ARGS__) #else //ifdef _LOGGING -#define LOGE(module_level,...) -#define LOGV(module_level,...) -#define LOGD(module_level,...) -#define LOGI(module_level,...) -#define LOGS(module_level,...) -#define LOGP(module_level,...) +#define LOGE(module_level, ...) +#define LOGV(module_level, ...) +#define LOGD(module_level, ...) +#define LOGI(module_level, ...) +#define LOGS(module_level, ...) +#define LOGP(module_level, ...) #endif //ifdef _LOGGING diff --git a/osal/Osal.h b/osal/Osal.h index f8fb268..5906d32 100644 --- a/osal/Osal.h +++ b/osal/Osal.h @@ -314,9 +314,9 @@ void OsaIrqResetCount(void); #if defined(__KERNEL__) void OsaModule_Open(void); void OsaModule_Close(void); -int OsaModule_RegisterDev(const char* devname,int iminor_cnt,struct file_operations *fp_op); -int OsaModule_UnRegisterDev(unsigned int devId, const char* devname,int iminor_cnt); -int OsaModule_Remap_page_range(struct vm_area_struct *vma,unsigned int uiaddr); +int OsaModule_RegisterDev(const char* devname, int iminor_cnt, struct file_operations *fp_op); +int OsaModule_UnRegisterDev(unsigned int devId, const char* devname, int iminor_cnt); +int OsaModule_Remap_page_range(struct vm_area_struct *vma, unsigned int uiaddr); /*added by tukho.kim@samsung.com 080714 */ /*modified by tukho.kim@samsung.com 090818 */ @@ -344,8 +344,8 @@ int OsaModule_Remap_page_range(struct vm_area_struct *vma,unsigned int uiaddr); * OSAL_DCACHE_XXX are not supported. Do not use. */ static void __attribute__((unused)) staOsaWarnDeprecatedFunction(const char *func, const char *caller) { - printk (KERN_WARNING "[WARNING]\n"); - printk (KERN_WARNING "\tcaller=%s. %s is not support. Do not use!\n", caller, func); + printk(KERN_WARNING "[WARNING]\n"); + printk(KERN_WARNING "\tcaller=%s. %s is not support. Do not use!\n", caller, func); } #define OSAL_DCACHE_FLUSH() staOsaWarnDeprecatedFunction("OSAL_DCACHE_FLUSH", __FUNCTION__) diff --git a/simulatordaemon/inc/ClientCommands/CommandBase.h b/simulatordaemon/inc/ClientCommands/CommandBase.h index a50a54a..01137d4 100644 --- a/simulatordaemon/inc/ClientCommands/CommandBase.h +++ b/simulatordaemon/inc/ClientCommands/CommandBase.h @@ -51,7 +51,6 @@ public: */ CommandBase(TEEContext *TEECtx) : pTEECtx(TEECtx) { - } /** * Command Base Execute for commands received from TEECLib. diff --git a/simulatordaemon/inc/ClientCommands/CommandInvokeCommand.h b/simulatordaemon/inc/ClientCommands/CommandInvokeCommand.h index 6dfcdf7..dd4bf2a 100644 --- a/simulatordaemon/inc/ClientCommands/CommandInvokeCommand.h +++ b/simulatordaemon/inc/ClientCommands/CommandInvokeCommand.h @@ -39,7 +39,6 @@ public: CommandInvokeCommand(InvokeCommandData data, TEEContext *TEECtx); void execute(); virtual ~CommandInvokeCommand(); - }; #endif /* COMMANDINVOKECOMMAND_H_ */ diff --git a/simulatordaemon/inc/ClientCommands/CommandInvokeTACommand.h b/simulatordaemon/inc/ClientCommands/CommandInvokeTACommand.h index 9c53693..3b296ea 100644 --- a/simulatordaemon/inc/ClientCommands/CommandInvokeTACommand.h +++ b/simulatordaemon/inc/ClientCommands/CommandInvokeTACommand.h @@ -39,7 +39,6 @@ public: CommandInvokeTACommand(IntTAInvokeCommandData data, TEEContext *TEECtx); void execute(); virtual ~CommandInvokeTACommand(); - }; #endif /* COMMANDINVOKETACOMMAND_H_ */ diff --git a/simulatordaemon/inc/ClientCommands/CommandPanic.h b/simulatordaemon/inc/ClientCommands/CommandPanic.h index d25c345..817cc3c 100644 --- a/simulatordaemon/inc/ClientCommands/CommandPanic.h +++ b/simulatordaemon/inc/ClientCommands/CommandPanic.h @@ -39,7 +39,6 @@ public: CommandPanic(IntTAPanicData data, TEEContext *TEECtx); void execute(); virtual ~CommandPanic(); - }; #endif /* COMMANDPANIC_H_ */ diff --git a/simulatordaemon/inc/ClientCommands/CommandRegSharedMem.h b/simulatordaemon/inc/ClientCommands/CommandRegSharedMem.h index 93ee941..bf836d3 100644 --- a/simulatordaemon/inc/ClientCommands/CommandRegSharedMem.h +++ b/simulatordaemon/inc/ClientCommands/CommandRegSharedMem.h @@ -39,7 +39,6 @@ public: CommandRegSharedMem(RegSharedMemData data, TEEContext *TEECtx); void execute(); virtual ~CommandRegSharedMem(); - }; #endif /* COMMANDREGSHAREDMEM_H_ */ diff --git a/simulatordaemon/inc/ClientCommands/CommandRelSharedMem.h b/simulatordaemon/inc/ClientCommands/CommandRelSharedMem.h index c9af09d..b79b28f 100644 --- a/simulatordaemon/inc/ClientCommands/CommandRelSharedMem.h +++ b/simulatordaemon/inc/ClientCommands/CommandRelSharedMem.h @@ -39,7 +39,6 @@ public: CommandRelSharedMem(RelSharedMemData data, TEEContext *TEECtx); void execute(); virtual ~CommandRelSharedMem(); - }; #endif /* COMMANDRELSHAREDMEM_H_ */ diff --git a/simulatordaemon/inc/ClientCommands/CommandReqCancellation.h b/simulatordaemon/inc/ClientCommands/CommandReqCancellation.h index dffb0d3..c563cd1 100644 --- a/simulatordaemon/inc/ClientCommands/CommandReqCancellation.h +++ b/simulatordaemon/inc/ClientCommands/CommandReqCancellation.h @@ -39,7 +39,6 @@ public: CommandReqCancellation(ReqCancellationData data, TEEContext *TEECtx); void execute(); virtual ~CommandReqCancellation(); - }; #endif /* COMMANDREQCANCELLATION_H_ */ diff --git a/simulatordaemon/inc/ResponseCommands/ResCommandInvokeCommand.h b/simulatordaemon/inc/ResponseCommands/ResCommandInvokeCommand.h index 2893b38..2a13c51 100644 --- a/simulatordaemon/inc/ResponseCommands/ResCommandInvokeCommand.h +++ b/simulatordaemon/inc/ResponseCommands/ResCommandInvokeCommand.h @@ -40,7 +40,6 @@ public: std::map *sessionMap); void execute(); virtual ~ResCommandInvokeCommand(); - }; #endif /* RESCOMMANDINVOKECOMMAND_H_ */ diff --git a/simulatordaemon/inc/ResponseCommands/ResCommandReqCancellation.h b/simulatordaemon/inc/ResponseCommands/ResCommandReqCancellation.h index a9b85a4..e6f79a0 100644 --- a/simulatordaemon/inc/ResponseCommands/ResCommandReqCancellation.h +++ b/simulatordaemon/inc/ResponseCommands/ResCommandReqCancellation.h @@ -40,7 +40,6 @@ public: std::map *sessionMap); void execute(); virtual ~ResCommandReqCancellation(); - }; #endif /* RESCOMMANDREQCANCELLATION_H_ */ diff --git a/simulatordaemon/src/ClientCommands/CommandCloseSession.cpp b/simulatordaemon/src/ClientCommands/CommandCloseSession.cpp index d73313a..b80fbeb 100644 --- a/simulatordaemon/src/ClientCommands/CommandCloseSession.cpp +++ b/simulatordaemon/src/ClientCommands/CommandCloseSession.cpp @@ -58,5 +58,4 @@ void CommandCloseSession::execute() { } CommandCloseSession::~CommandCloseSession() { - } diff --git a/simulatordaemon/src/ClientCommands/CommandCloseTASession.cpp b/simulatordaemon/src/ClientCommands/CommandCloseTASession.cpp index d3b8a49..8e2742d 100644 --- a/simulatordaemon/src/ClientCommands/CommandCloseTASession.cpp +++ b/simulatordaemon/src/ClientCommands/CommandCloseTASession.cpp @@ -50,5 +50,4 @@ void CommandCloseTASession::execute() { } CommandCloseTASession::~CommandCloseTASession() { - } diff --git a/simulatordaemon/src/ClientCommands/CommandInvokeCommand.cpp b/simulatordaemon/src/ClientCommands/CommandInvokeCommand.cpp index 584e9e3..23cb5a2 100644 --- a/simulatordaemon/src/ClientCommands/CommandInvokeCommand.cpp +++ b/simulatordaemon/src/ClientCommands/CommandInvokeCommand.cpp @@ -57,5 +57,4 @@ void CommandInvokeCommand::execute() { } CommandInvokeCommand::~CommandInvokeCommand() { - } diff --git a/simulatordaemon/src/ClientCommands/CommandInvokeTACommand.cpp b/simulatordaemon/src/ClientCommands/CommandInvokeTACommand.cpp index 2184802..31d5f73 100644 --- a/simulatordaemon/src/ClientCommands/CommandInvokeTACommand.cpp +++ b/simulatordaemon/src/ClientCommands/CommandInvokeTACommand.cpp @@ -54,5 +54,4 @@ void CommandInvokeTACommand::execute() { } CommandInvokeTACommand::~CommandInvokeTACommand() { - } diff --git a/simulatordaemon/src/ClientCommands/CommandOpenTASession.cpp b/simulatordaemon/src/ClientCommands/CommandOpenTASession.cpp index 8b2cb5d..5f6f648 100644 --- a/simulatordaemon/src/ClientCommands/CommandOpenTASession.cpp +++ b/simulatordaemon/src/ClientCommands/CommandOpenTASession.cpp @@ -46,7 +46,6 @@ CommandOpenTASession::CommandOpenTASession(IntTAOpenSessionData data, * @param none */ CommandOpenTASession::~CommandOpenTASession() { - } void CommandOpenTASession::execute() { diff --git a/simulatordaemon/src/ClientCommands/MakeCommand.cpp b/simulatordaemon/src/ClientCommands/MakeCommand.cpp index e996d0d..6ea78cb 100644 --- a/simulatordaemon/src/ClientCommands/MakeCommand.cpp +++ b/simulatordaemon/src/ClientCommands/MakeCommand.cpp @@ -122,7 +122,6 @@ CommandBasePtr MakeCommand::getCommand(TEE_CMD teecmd, void* teedata, } MakeCommand::~MakeCommand() { - } /** @@ -134,7 +133,6 @@ MakeCommand::~MakeCommand() { * */ uint32_t MakeCommand::getDataSize(TEE_CMD command) { - uint32_t size = -1; switch (command) { case INITIALIZE_CONTEXT: diff --git a/simulatordaemon/src/ConnectionSession.cpp b/simulatordaemon/src/ConnectionSession.cpp index 5b2aa69..31fb181 100644 --- a/simulatordaemon/src/ConnectionSession.cpp +++ b/simulatordaemon/src/ConnectionSession.cpp @@ -51,7 +51,7 @@ void ConnectionSession::start() { #ifdef _CYNARA_INTEGRATION /* Check if client has cynara permission */ const string privilege("http://tizen.org/privilege/tee.client"); - if (! secContext.clientHasCynaraPermission(privilege)) { + if (!secContext.clientHasCynaraPermission(privilege)) { LOGE(SIM_DAEMON, "Client has no permission to use TEE"); return; } @@ -98,7 +98,7 @@ void ConnectionSession::handleRead(const boost::system::error_code& error, case CMD_READ: { // Identify command command = (TEE_CMD)clientData.at(0); - LOGD(SIM_DAEMON, "Command received: %d", (uint32_t )command); + LOGD(SIM_DAEMON, "Command received: %d", (uint32_t)command); // Calculate pending numbers of bytes pending to be read only for commands int32_t data_size = MakeCommand::getDataSize(command); @@ -111,14 +111,11 @@ void ConnectionSession::handleRead(const boost::system::error_code& error, boost::bind(&ConnectionSession::handleRead, shared_from_this(), boost::asio::placeholders::error, boost::asio::placeholders::bytes_transferred)); - } - - else if (-1 == data_size) { + } else if (-1 == data_size) { // else case is invalid command // TODO: Identify the correct behavior; what to do when invalid command is received? LOGE(SIM_DAEMON, "Invalid command received!"); } else if (0 == data_size) { - // reset state to read new command currentState = CMD_READ; // read command and register callback to read data @@ -187,10 +184,9 @@ void ConnectionSession::handleRead(const boost::system::error_code& error, */ TEEC_Result ConnectionSession::write(TEE_CMD cmd, char* data, size_t size) { LOGD(SIM_DAEMON, "Entry"); - TEEC_Result result = TEEC_ERROR_COMMUNICATION; boost::system::error_code error = boost::asio::error::host_not_found; - pthread_mutex_lock (&connLock); + pthread_mutex_lock(&connLock); // Send command to TEECLib for CA boost::asio::write(clientSocket, boost::asio::buffer((char*)&cmd, sizeof(char)), @@ -202,7 +198,8 @@ TEEC_Result ConnectionSession::write(TEE_CMD cmd, char* data, size_t size) { boost::asio::transfer_all(), error); if (!error) result = TEEC_SUCCESS; - else { + else + { LOGE(SIM_DAEMON, "Error in writing Data to CA"); LOGE(SIM_DAEMON, "Response returned with error code %d", error.value()); LOGE(SIM_DAEMON, "Response returned with error code %s", @@ -225,7 +222,7 @@ SecurityContext ConnectionSession::getSecurityContext(){ ConnectionSession::~ConnectionSession() { LOGD(SIM_DAEMON, "Entry"); // Destory the lock for write (connLock) - pthread_mutex_destroy (&connLock); + pthread_mutex_destroy(&connLock); // delete Context delete TEECtx; TEECtx = NULL; diff --git a/simulatordaemon/src/ResponseCommands/ResCommandCloseSession.cpp b/simulatordaemon/src/ResponseCommands/ResCommandCloseSession.cpp index 0c142ff..896d008 100644 --- a/simulatordaemon/src/ResponseCommands/ResCommandCloseSession.cpp +++ b/simulatordaemon/src/ResponseCommands/ResCommandCloseSession.cpp @@ -78,7 +78,9 @@ void ResCommandCloseSession::execute() { LOGE(SIM_DAEMON, "Destroy sendRequestToTA FAILED"); (session->getTAInstance())->killTA(); } - } else break; + } else { + break; + } } TAFact->mTAInstanceMap.erase(itTAMap); break; @@ -118,5 +120,4 @@ void ResCommandCloseSession::execute() { } ResCommandCloseSession::~ResCommandCloseSession() { - } diff --git a/simulatordaemon/src/ResponseCommands/ResCommandInvokeCommand.cpp b/simulatordaemon/src/ResponseCommands/ResCommandInvokeCommand.cpp index 1a770d7..057d99e 100644 --- a/simulatordaemon/src/ResponseCommands/ResCommandInvokeCommand.cpp +++ b/simulatordaemon/src/ResponseCommands/ResCommandInvokeCommand.cpp @@ -118,5 +118,4 @@ void ResCommandInvokeCommand::execute() { } ResCommandInvokeCommand::~ResCommandInvokeCommand() { - } diff --git a/simulatordaemon/src/ResponseCommands/ResMakeCommand.cpp b/simulatordaemon/src/ResponseCommands/ResMakeCommand.cpp index 53e61de..f0a7f67 100644 --- a/simulatordaemon/src/ResponseCommands/ResMakeCommand.cpp +++ b/simulatordaemon/src/ResponseCommands/ResMakeCommand.cpp @@ -74,7 +74,6 @@ ResCommandBasePtr ResMakeCommand::getCommand(SIM_COMMAND tacmd, void* tadata, } ResMakeCommand::~ResMakeCommand() { - } /** @@ -86,7 +85,6 @@ ResMakeCommand::~ResMakeCommand() { * */ uint32_t ResMakeCommand::getDataSize(SIM_COMMAND command) { - uint32_t size = -1; switch (command) { case CREATE: diff --git a/simulatordaemon/src/SecurityContext.cpp b/simulatordaemon/src/SecurityContext.cpp index c7d8946..3cd4e1a 100644 --- a/simulatordaemon/src/SecurityContext.cpp +++ b/simulatordaemon/src/SecurityContext.cpp @@ -55,7 +55,6 @@ pthread_mutex_t cynara_mutex = PTHREAD_MUTEX_INITIALIZER; std::string SecurityContext::getCaFullPathFromPkgId(char* pkgid) { - std::string path; tzplatform_variable ids[3] = {TZ_USER_APP, TZ_SYS_RW_APP, TZ_SYS_RO_APP}; diff --git a/simulatordaemon/src/Session.cpp b/simulatordaemon/src/Session.cpp index 7b6906d..e9b84d3 100644 --- a/simulatordaemon/src/Session.cpp +++ b/simulatordaemon/src/Session.cpp @@ -90,7 +90,6 @@ TEEC_Result Session::writeResponse(TEE_CMD command, char* data, size_t size) { * @param data OpenSessionData type of data for opening a session */ TEEC_Result Session::createSession(OpenSessionData data) { - uint32_t i, type; TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -288,7 +287,6 @@ void Session::handleCancel(ReqCancellationData data) { * Session clean up. Called before Session destructor to clean the session */ TEEC_Result Session::finalize(uint32_t contextID) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -343,7 +341,9 @@ TEEC_Result Session::finalize(uint32_t contextID) { LOGE(SIM_DAEMON, "Destroy sendRequestToTA FAILED"); mTAInstance->killTA(); } - } else break; + } else { + break; + } } // Erase TA Instance from TA FActory's Instance map TAFact->mTAInstanceMap.erase(itTAMap); diff --git a/simulatordaemon/src/TABinaryManager/TABinaryManager.h b/simulatordaemon/src/TABinaryManager/TABinaryManager.h index c1149de..bf7366e 100644 --- a/simulatordaemon/src/TABinaryManager/TABinaryManager.h +++ b/simulatordaemon/src/TABinaryManager/TABinaryManager.h @@ -58,7 +58,6 @@ typedef struct { * Class definitions *-----------------------------------------------------------------------------*/ class TABinaryManager { - private: static TABinaryManager *instance; std::string base64_chars; diff --git a/simulatordaemon/src/TABinaryManager/TAManifest.cpp b/simulatordaemon/src/TABinaryManager/TAManifest.cpp index dc4fb21..90eb3bb 100644 --- a/simulatordaemon/src/TABinaryManager/TAManifest.cpp +++ b/simulatordaemon/src/TABinaryManager/TAManifest.cpp @@ -37,11 +37,9 @@ using namespace rapidxml; *-----------------------------------------------------------------------------*/ TAManifest::TAManifest() { - } bool TAManifest::processXML(const string &xmlManifestPath) { - bool ret = false; // Open file std::ifstream xmlfile(xmlManifestPath.c_str()); @@ -69,7 +67,7 @@ bool TAManifest::processXML(const string &xmlManifestPath) { .compare("true") == 0 ? true : false; properties.general.multiSession = string(propertiesGeneral->first_attribute("multiSession")->value()) .compare("true") == 0 ? true : false; - properties.general.instanceKeepAlive =string(propertiesGeneral->first_attribute("instanceKeepAlive")->value()) + properties.general.instanceKeepAlive = string(propertiesGeneral->first_attribute("instanceKeepAlive")->value()) .compare("true") == 0 ? true : false; sstream.clear(); @@ -97,7 +95,6 @@ bool TAManifest::processXML(const string &xmlManifestPath) { properties.extension.launchMode = string(propertiesExtension->first_attribute("launchMode")->value()); } - } // 2. POLICY node = doc.first_node("manifest")->first_node("policy"); @@ -131,7 +128,6 @@ bool TAManifest::processXML(const string &xmlManifestPath) { policy.usesPermission.push_back(string(childnode->first_attribute("name")->value())); } } - } // 3. TA ENC node = doc.first_node("manifest")->first_node("taEncryption"); @@ -221,10 +217,8 @@ void TAManifest::printProcessedData() const { std::cout << "[SIM_DAEMON] information.description: " << information.description << endl; std::cout << "[SIM_DAEMON] information.terms: " << information.terms << endl; - } TAManifest::~TAManifest() { - } diff --git a/simulatordaemon/src/TABinaryManager/TAManifest.h b/simulatordaemon/src/TABinaryManager/TAManifest.h index b2c5845..045c37a 100644 --- a/simulatordaemon/src/TABinaryManager/TAManifest.h +++ b/simulatordaemon/src/TABinaryManager/TAManifest.h @@ -92,7 +92,6 @@ typedef struct { *-----------------------------------------------------------------------------*/ class TAManifest { - public: StructProperties properties; StructPolicy policy; @@ -104,6 +103,5 @@ public: bool processXML(const string &xmlManifest); void printProcessedData() const; virtual ~TAManifest(); - }; #endif /* TAMANIFEST_H_ */ diff --git a/simulatordaemon/src/TABinaryManager/TAUnpack.cpp b/simulatordaemon/src/TABinaryManager/TAUnpack.cpp index f759477..e2aa854 100644 --- a/simulatordaemon/src/TABinaryManager/TAUnpack.cpp +++ b/simulatordaemon/src/TABinaryManager/TAUnpack.cpp @@ -44,7 +44,6 @@ TAUnpack *TAUnpack::instance = NULL; * Member functions *-----------------------------------------------------------------------------*/ TAUnpack::TAUnpack() { - } TAUnpack* TAUnpack::getInstance() { @@ -134,7 +133,6 @@ int TAUnpack::unpackTA(string path, string uuid) { } void TAUnpack::fixHeaderEndianness(TAPackageHeaderV2* header) { - char* headerptr = (char*)header; for (unsigned int i = 0; i < sizeof(TAPackageHeaderV2); i += sizeof(unsigned int)) { @@ -145,7 +143,6 @@ void TAUnpack::fixHeaderEndianness(TAPackageHeaderV2* header) { headerptr[i + 3] = temp1; headerptr[i + 2] = temp2; } - } /** diff --git a/simulatordaemon/src/TABinaryManager/TestMain.cpp b/simulatordaemon/src/TABinaryManager/TestMain.cpp index 2d9e1dc..f66443d 100644 --- a/simulatordaemon/src/TABinaryManager/TestMain.cpp +++ b/simulatordaemon/src/TABinaryManager/TestMain.cpp @@ -63,7 +63,6 @@ int test_main() { } // Execute image case 3: { - break; } // Test TA Binary Manager @@ -84,7 +83,6 @@ int test_main() { break; } - } } } catch (std::exception& e) { diff --git a/simulatordaemon/src/TAFactory.cpp b/simulatordaemon/src/TAFactory.cpp index cc6b3b2..f55e11d 100644 --- a/simulatordaemon/src/TAFactory.cpp +++ b/simulatordaemon/src/TAFactory.cpp @@ -59,7 +59,6 @@ TAFactory::TAFactory() { * instance and return the instance else return the already created instance. */ TAFactory* TAFactory::getInstance() { - LOGD(SIM_DAEMON, "Entry"); pthread_mutex_lock(&instLock); @@ -79,7 +78,6 @@ TAFactory* TAFactory::getInstance() { * with it */ TAInstancePtr TAFactory::getTAInstance(TEEC_UUID uuid, ISession* session) { - TAInstancePtr TAInst; bool result; LOGD(SIM_DAEMON, "Entry"); @@ -91,8 +89,8 @@ TAInstancePtr TAFactory::getTAInstance(TEEC_UUID uuid, ISession* session) { // Change to upper char. TA list has upper char. locale loc; - for (size_t i=0; igetSecurityContext()) { - LOGD(SIM_DAEMON, "ContextID: %d", contextID); /* Initialize the locks for shared memory list (mShmList) and Session map @@ -67,7 +66,6 @@ TEEContext::TEEContext(uint32_t contextID, IConnectionSession* connSession): * @param data data sent from TEECLib for InitContext */ TEEC_Result TEEContext::initContext(InitContextData* data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -111,7 +109,6 @@ TEEC_Result TEEContext::initContext(InitContextData* data) { * @param data data sent from TEECLib for FinalizeContext */ void TEEContext::finContext(FinalizeContextData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -165,7 +162,6 @@ void TEEContext::finContext(FinalizeContextData data) { * @param data data sent from TEECLib for OpenSession */ TEEC_Result TEEContext::openSession(OpenSessionData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -221,7 +217,6 @@ TEEC_Result TEEContext::openSession(OpenSessionData data) { * @param data data sent from TEECLib for InvokeCommand */ TEEC_Result TEEContext::invokeCommand(InvokeCommandData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); data.returnOrigin = TEEC_ORIGIN_TEE; @@ -266,7 +261,6 @@ TEEC_Result TEEContext::invokeCommand(InvokeCommandData data) { * @param data data sent from TEECLib for RequestCancellation */ void TEEContext::reqCancel(ReqCancellationData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -302,7 +296,6 @@ void TEEContext::reqCancel(ReqCancellationData data) { * @param data data sent from TEECLib for CloseSession */ TEEC_Result TEEContext::closeSession(CloseSessionData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -351,7 +344,6 @@ TEEC_Result TEEContext::closeSession(CloseSessionData data) { * @param data data sent from SSFLib for OpenTASession */ TEEC_Result TEEContext::openTASession(IntTAOpenSessionData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -432,7 +424,6 @@ TEEC_Result TEEContext::openTASession(IntTAOpenSessionData data) { * @param data data sent from SSFLib for CloseTASession */ void TEEContext::closeTASession(IntTACloseSessionData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; map::iterator it; LOGD(SIM_DAEMON, "Entry"); @@ -470,7 +461,6 @@ void TEEContext::closeTASession(IntTACloseSessionData data) { * @param data data sent from SSFLib for InvokeTACommand */ TEEC_Result TEEContext::invokeTACommand(IntTAInvokeCommandData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); @@ -517,7 +507,6 @@ TEEC_Result TEEContext::invokeTACommand(IntTAInvokeCommandData data) { * @param data data sent from TEECLib for RegisterSharedMemory */ TEEC_Result TEEContext::registerSharedMemory(RegSharedMemData data) { - TEEC_Result result = TEEC_ERROR_GENERIC; LOGD(SIM_DAEMON, "Entry"); diff --git a/ssflib/dep/cryptocore/include/CC_API.h b/ssflib/dep/cryptocore/include/CC_API.h index a99bc7d..ab5aafc 100644 --- a/ssflib/dep/cryptocore/include/CC_API.h +++ b/ssflib/dep/cryptocore/include/CC_API.h @@ -63,46 +63,46 @@ typedef struct _CryptoCoreContainer CryptoCoreCTX *ctx; /**< Algorithm */ // Pseudo Random Number Generation (ANSI X9.17) - int (*PRNG_seed) (struct _CryptoCoreContainer *crt, cc_u8 *seed); - int (*PRNG_get) (struct _CryptoCoreContainer *crt, cc_u32 bitlength, cc_u8 *data); + int (*PRNG_seed)(struct _CryptoCoreContainer *crt, cc_u8 *seed); + int (*PRNG_get)(struct _CryptoCoreContainer *crt, cc_u32 bitlength, cc_u8 *data); // Message Digest (MD5, SHA-1) - int (*MD_init) (struct _CryptoCoreContainer *crt); - int (*MD_update) (struct _CryptoCoreContainer *crt, cc_u8 *msg, cc_u32 msglen); - int (*MD_final) (struct _CryptoCoreContainer *crt, cc_u8 *output); - int (*MD_getHASH) (struct _CryptoCoreContainer *crt, cc_u8 *msg, cc_u32 msglen, cc_u8 *output); + int (*MD_init)(struct _CryptoCoreContainer *crt); + int (*MD_update)(struct _CryptoCoreContainer *crt, cc_u8 *msg, cc_u32 msglen); + int (*MD_final)(struct _CryptoCoreContainer *crt, cc_u8 *output); + int (*MD_getHASH)(struct _CryptoCoreContainer *crt, cc_u8 *msg, cc_u32 msglen, cc_u8 *output); // Message Authentication Code (CMAC, HMAC MD5, HMAC SHA-1) - int (*MAC_init) (struct _CryptoCoreContainer *crt, cc_u8 *Key, cc_u32 KeyLen); - int (*MAC_update) (struct _CryptoCoreContainer *crt, cc_u8 *msg, cc_u32 msgLen); - int (*MAC_final) (struct _CryptoCoreContainer *crt, cc_u8 *output, cc_u32 *outputLen); - int (*MAC_getMAC) (struct _CryptoCoreContainer *crt, cc_u8 *Key, cc_u32 KeyLen, cc_u8 *msg, cc_u32 msgLen, cc_u8 *output, cc_u32 *outputLen); + int (*MAC_init)(struct _CryptoCoreContainer *crt, cc_u8 *Key, cc_u32 KeyLen); + int (*MAC_update)(struct _CryptoCoreContainer *crt, cc_u8 *msg, cc_u32 msgLen); + int (*MAC_final)(struct _CryptoCoreContainer *crt, cc_u8 *output, cc_u32 *outputLen); + int (*MAC_getMAC)(struct _CryptoCoreContainer *crt, cc_u8 *Key, cc_u32 KeyLen, cc_u8 *msg, cc_u32 msgLen, cc_u8 *output, cc_u32 *outputLen); // Key Exchange (DH, ECDH) - int (*DH_GenerateParam) (struct _CryptoCoreContainer *crt, cc_u8* pPrime, cc_u32 nPrimeLen, cc_u8* pGenerator); - int (*DH_SetParam) (struct _CryptoCoreContainer *crt, cc_u8* pPrime, cc_u32 nPrimeLen, cc_u8* nGenerator, cc_u32 nGeneratorLen); - int (*DH_Gen1stPhaseKey) (struct _CryptoCoreContainer *crt, cc_u8* pPriv, cc_u8* pPub); - int (*DH_GenAuthKey) (struct _CryptoCoreContainer *crt, cc_u8* pPriv, cc_u8* pPub, cc_u8* pSharedSecret); - int (*ECDH_Gen1stPhaseKey) (struct _CryptoCoreContainer *crt, cc_u8* pDH_Xk, cc_u8* pDH1stPhaseKey); - int (*ECDH_GenAuthKey) (struct _CryptoCoreContainer *crt, cc_u8* pchXk, cc_u8* pchYv, cc_u8* pchKauth); + int (*DH_GenerateParam)(struct _CryptoCoreContainer *crt, cc_u8* pPrime, cc_u32 nPrimeLen, cc_u8* pGenerator); + int (*DH_SetParam)(struct _CryptoCoreContainer *crt, cc_u8* pPrime, cc_u32 nPrimeLen, cc_u8* nGenerator, cc_u32 nGeneratorLen); + int (*DH_Gen1stPhaseKey)(struct _CryptoCoreContainer *crt, cc_u8* pPriv, cc_u8* pPub); + int (*DH_GenAuthKey)(struct _CryptoCoreContainer *crt, cc_u8* pPriv, cc_u8* pPub, cc_u8* pSharedSecret); + int (*ECDH_Gen1stPhaseKey)(struct _CryptoCoreContainer *crt, cc_u8* pDH_Xk, cc_u8* pDH1stPhaseKey); + int (*ECDH_GenAuthKey)(struct _CryptoCoreContainer *crt, cc_u8* pchXk, cc_u8* pchYv, cc_u8* pchKauth); // Symmetric Encryption (DES, 3DES, AES, RC4, SNOW) // mode example : ENC_ECB, DEC_ECB, ENC_CBC, DEC_CBC, ... - int (*SE_init) (struct _CryptoCoreContainer *crt, cc_u32 mode, cc_u32 PADDING, cc_u8 *key, cc_u32 keysize, cc_u8 *IV); - int (*SE_process) (struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); - int (*SE_final) (struct _CryptoCoreContainer *crt, cc_u8 *input, cc_u32 inputLen, cc_u8 *output, cc_u32 *outputLen); + int (*SE_init)(struct _CryptoCoreContainer *crt, cc_u32 mode, cc_u32 PADDING, cc_u8 *key, cc_u32 keysize, cc_u8 *IV); + int (*SE_process)(struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); + int (*SE_final)(struct _CryptoCoreContainer *crt, cc_u8 *input, cc_u32 inputLen, cc_u8 *output, cc_u32 *outputLen); // Simple AES Function - int (*SE_EncryptOneBlock) (cc_u8 *cipherText, cc_u8 *plainText, cc_u8 *UserKey); - int (*SE_DecryptOneBlock) (cc_u8 *plainText, cc_u8 *cipherText, cc_u8 *UserKey); + int (*SE_EncryptOneBlock)(cc_u8 *cipherText, cc_u8 *plainText, cc_u8 *UserKey); + int (*SE_DecryptOneBlock)(cc_u8 *plainText, cc_u8 *cipherText, cc_u8 *UserKey); // Asymmetric Encryption (RSA, Elgamal, EC-Elgamal) - int (*AE_encrypt) (struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); - int (*AE_decrypt) (struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); - int (*AE_decryptByCRT) (struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); + int (*AE_encrypt)(struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); + int (*AE_decrypt)(struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); + int (*AE_decryptByCRT)(struct _CryptoCoreContainer *crt, cc_u8 *in, cc_u32 inLen, cc_u8 *out, cc_u32 *outLen); // Digital Signature (DSA, EC-DSA) - int (*DS_sign) (struct _CryptoCoreContainer *crt, cc_u8 *hash, cc_u32 hashLen, cc_u8 *signature, cc_u32 *signLen); - int (*DS_verify) (struct _CryptoCoreContainer *crt, cc_u8 *hash, cc_u32 hashLen, cc_u8 *signature, cc_u32 signLen, int *result); + int (*DS_sign)(struct _CryptoCoreContainer *crt, cc_u8 *hash, cc_u32 hashLen, cc_u8 *signature, cc_u32 *signLen); + int (*DS_verify)(struct _CryptoCoreContainer *crt, cc_u8 *hash, cc_u32 hashLen, cc_u8 *signature, cc_u32 signLen, int *result); int (*DSA_genParam)( struct _CryptoCoreContainer *crt, cc_u32 T_Siz, cc_u8 *DSA_P_Data, cc_u32 *DSA_P_Len, @@ -210,7 +210,6 @@ typedef struct _CryptoCoreContainer cc_u8* PUB_X_Data, cc_u32 PUB_X_Len, cc_u8* PUB_Y_Data, cc_u32 PUB_Y_Len ); - } CryptoCoreContainer; #ifdef __cplusplus @@ -251,4 +250,4 @@ void ECRYPTO_API *CCMalloc(int siz); #endif -/***************************** End of File *****************************/ \ No newline at end of file +/***************************** End of File *****************************/ diff --git a/ssflib/dep/cryptocore/include/CC_Context.h b/ssflib/dep/cryptocore/include/CC_Context.h index 04741ab..2de9c59 100644 --- a/ssflib/dep/cryptocore/include/CC_Context.h +++ b/ssflib/dep/cryptocore/include/CC_Context.h @@ -334,7 +334,6 @@ typedef struct { cc_u32 t; cc_u32 endian; //0 if little endian, 1 if bigendian - } SDRM_SNOW2Context; //////////////////////////////////////////////////////////////////////////// @@ -395,4 +394,4 @@ typedef struct { #endif -/***************************** End of File *****************************/ \ No newline at end of file +/***************************** End of File *****************************/ diff --git a/ssflib/dep/cryptocore/include/base/cc_bignum.h b/ssflib/dep/cryptocore/include/base/cc_bignum.h index 7aff057..c18b4c8 100644 --- a/ssflib/dep/cryptocore/include/base/cc_bignum.h +++ b/ssflib/dep/cryptocore/include/base/cc_bignum.h @@ -43,7 +43,7 @@ #define SDRM_CheckBitUINT32(A, k) (0x01 & ((A)[(k) >> 5] >> ((k) & 31))) /*! @brief get k-th byte from cc_u32 array A */ -#define SDRM_CheckByteUINT32(A, k) (cc_u8)(0xff & (A[(k) >> 2] >> (((k) & 3 ) << 3))) +#define SDRM_CheckByteUINT32(A, k) (cc_u8)(0xff & (A[(k) >> 2] >> (((k) & 3) << 3))) #define SDRM_isEven0(X) (((X)[0] & 0x01) == 0) #define SDRM_isOdd0(X) (((X)[0] & 0x01) == 1) @@ -52,7 +52,7 @@ for (i = 0; i < (B); i++) { \ if (++A[i] != 0) break; \ } \ - } while(0) \ + } while (0) \ //////////////////////////////////////////////////////////////////////////// // MACROs for cc_u32 Evaluation @@ -70,7 +70,7 @@ #define SDRM_DIGIT_Mul(Dest, Src1, Src2) do { \ (Dest)[0] = (cc_u32) ((cc_u64)(Src1) * (Src2)); \ (Dest)[1] = (cc_u32)(((cc_u64)(Src1) * (Src2)) >> SDRM_BitsInDWORD); \ - } while(0) + } while (0) #else void SDRM_DIGIT_Mul(cc_u32 *Dest, cc_u32 Src1, cc_u32 Src2); #endif @@ -113,7 +113,7 @@ cc_u32 SDRM_DIGIT_Mod(cc_u32 Src1, cc_u32 Src2, cc_u32 Div); */ #define SDRM_DWD_Copy(Dest, Src, Size) do { \ memcpy(Dest, Src, SDRM_SIZE_OF_DWORD * Size); \ - } while(0) + } while (0) //////////////////////////////////////////////////////////////////////////// // MACROs for Big Number @@ -128,7 +128,7 @@ cc_u32 SDRM_DIGIT_Mod(cc_u32 Src1, cc_u32 Src2, cc_u32 Div); * @fn SDRM_BN_FREE(X) * @brief free allocated memory */ -#define SDRM_BN_FREE(X) do {if (X) free(X);} while(0) +#define SDRM_BN_FREE(X) do {if (X) free(X);} while (0) /* * @fn SDRM_BN_OPTIMIZE_LENGTH(BN @@ -140,7 +140,7 @@ cc_u32 SDRM_DIGIT_Mod(cc_u32 Src1, cc_u32 Src2, cc_u32 Div); break; \ else \ (BN)->Length--; \ - } while(0) + } while (0) /* * @fn SDRM_IS_BN_NEGATIVE(X) * @brief check big number's sign @@ -153,20 +153,22 @@ cc_u32 SDRM_DIGIT_Mod(cc_u32 Src1, cc_u32 Src2, cc_u32 Div); /*! @brief count byte-length of big number */ #define SDRM_BN_GETBYTELEN(X, A) do { \ if (!((X)->Length)) (A) = 0; \ - else { \ + else \ + { \ (A) = (X)->Length * 4; \ while(SDRM_CheckByteUINT32((X)->pData, (A) - 1) == 0) {(A) -= 1;} \ } \ - } while(0) + } while (0) /*! @brief count bit-length of big number */ #define SDRM_BN_GETBITLEN(X, A) do { \ if (!((X)->Length)) (A) = 0; \ - else { \ + else \ + { \ (A) = (X)->Length * SDRM_BitsInDWORD; \ while(SDRM_CheckBitUINT32((X)->pData, (A) - 1) == 0) {(A) -= 1;} \ } \ - } while(0) + } while (0) //////////////////////////////////////////////////////////////////////////// // Global Variables diff --git a/ssflib/dep/cryptocore/include/base/cc_des.h b/ssflib/dep/cryptocore/include/base/cc_des.h index 9f35e53..f3180f5 100644 --- a/ssflib/dep/cryptocore/include/base/cc_des.h +++ b/ssflib/dep/cryptocore/include/base/cc_des.h @@ -47,34 +47,34 @@ #endif /*! @brief permutation operation */ -#define SDRM_PERM_OP(a,b,t,n,m) { \ - (t) = ((((a)>>(n))^(b))&(m)); \ +#define SDRM_PERM_OP(a, b, t, n, m) { \ + (t) = ((((a) >> (n))^(b))&(m)); \ (b) ^= (t); \ - (a) ^= ((t)<<(n)); \ + (a) ^= ((t) << (n)); \ } /*! @brief initial permutation */ -#define SDRM_IP(l,r) { \ +#define SDRM_IP(l, r) { \ cc_u32 tt; \ - SDRM_PERM_OP(r,l,tt, 4,0x0f0f0f0f); \ - SDRM_PERM_OP(l,r,tt,16,0x0000ffff); \ - SDRM_PERM_OP(r,l,tt, 2,0x33333333); \ - SDRM_PERM_OP(l,r,tt, 8,0x00ff00ff); \ - SDRM_PERM_OP(r,l,tt, 1,0x55555555); \ + SDRM_PERM_OP(r, l, tt, 4, 0x0f0f0f0f); \ + SDRM_PERM_OP(l, r, tt, 16, 0x0000ffff); \ + SDRM_PERM_OP(r, l, tt, 2, 0x33333333); \ + SDRM_PERM_OP(l, r, tt, 8, 0x00ff00ff); \ + SDRM_PERM_OP(r, l, tt, 1, 0x55555555); \ } /*! @brief inverse of initial permutation */ -#define SDRM_INV_IP(l,r) { \ +#define SDRM_INV_IP(l, r) { \ cc_u32 tt; \ - SDRM_PERM_OP(l,r,tt, 1,0x55555555); \ - SDRM_PERM_OP(r,l,tt, 8,0x00ff00ff); \ - SDRM_PERM_OP(l,r,tt, 2,0x33333333); \ - SDRM_PERM_OP(r,l,tt,16,0x0000ffff); \ - SDRM_PERM_OP(l,r,tt, 4,0x0f0f0f0f); \ + SDRM_PERM_OP(l, r, tt, 1, 0x55555555); \ + SDRM_PERM_OP(r, l, tt, 8, 0x00ff00ff); \ + SDRM_PERM_OP(l, r, tt, 2, 0x33333333); \ + SDRM_PERM_OP(r, l, tt, 16, 0x0000ffff); \ + SDRM_PERM_OP(l, r, tt, 4, 0x0f0f0f0f); \ } /*! @brief encrypt one round */ -#define SDRM_D_ENCRYPT(L,R) { \ +#define SDRM_D_ENCRYPT(L, R) { \ u = R ^ RoundKey[i][0]; \ t = R ^ RoundKey[i][1]; \ t = SDRM_rotr32(t, 4); \ @@ -112,155 +112,155 @@ static const cc_u8 SDRM_DES_KS_PC1[] = { static const cc_u32 SDRM_des_skb[8][64]={ { /* for C bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ - 0x00000000L,0x00000010L,0x20000000L,0x20000010L, - 0x00010000L,0x00010010L,0x20010000L,0x20010010L, - 0x00000800L,0x00000810L,0x20000800L,0x20000810L, - 0x00010800L,0x00010810L,0x20010800L,0x20010810L, - 0x00000020L,0x00000030L,0x20000020L,0x20000030L, - 0x00010020L,0x00010030L,0x20010020L,0x20010030L, - 0x00000820L,0x00000830L,0x20000820L,0x20000830L, - 0x00010820L,0x00010830L,0x20010820L,0x20010830L, - 0x00080000L,0x00080010L,0x20080000L,0x20080010L, - 0x00090000L,0x00090010L,0x20090000L,0x20090010L, - 0x00080800L,0x00080810L,0x20080800L,0x20080810L, - 0x00090800L,0x00090810L,0x20090800L,0x20090810L, - 0x00080020L,0x00080030L,0x20080020L,0x20080030L, - 0x00090020L,0x00090030L,0x20090020L,0x20090030L, - 0x00080820L,0x00080830L,0x20080820L,0x20080830L, - 0x00090820L,0x00090830L,0x20090820L,0x20090830L, + 0x00000000L, 0x00000010L, 0x20000000L, 0x20000010L, + 0x00010000L, 0x00010010L, 0x20010000L, 0x20010010L, + 0x00000800L, 0x00000810L, 0x20000800L, 0x20000810L, + 0x00010800L, 0x00010810L, 0x20010800L, 0x20010810L, + 0x00000020L, 0x00000030L, 0x20000020L, 0x20000030L, + 0x00010020L, 0x00010030L, 0x20010020L, 0x20010030L, + 0x00000820L, 0x00000830L, 0x20000820L, 0x20000830L, + 0x00010820L, 0x00010830L, 0x20010820L, 0x20010830L, + 0x00080000L, 0x00080010L, 0x20080000L, 0x20080010L, + 0x00090000L, 0x00090010L, 0x20090000L, 0x20090010L, + 0x00080800L, 0x00080810L, 0x20080800L, 0x20080810L, + 0x00090800L, 0x00090810L, 0x20090800L, 0x20090810L, + 0x00080020L, 0x00080030L, 0x20080020L, 0x20080030L, + 0x00090020L, 0x00090030L, 0x20090020L, 0x20090030L, + 0x00080820L, 0x00080830L, 0x20080820L, 0x20080830L, + 0x00090820L, 0x00090830L, 0x20090820L, 0x20090830L, }, { /* for C bits (numbered as per FIPS 46) 7 8 10 11 12 13 */ - 0x00000000L,0x02000000L,0x00002000L,0x02002000L, - 0x00200000L,0x02200000L,0x00202000L,0x02202000L, - 0x00000004L,0x02000004L,0x00002004L,0x02002004L, - 0x00200004L,0x02200004L,0x00202004L,0x02202004L, - 0x00000400L,0x02000400L,0x00002400L,0x02002400L, - 0x00200400L,0x02200400L,0x00202400L,0x02202400L, - 0x00000404L,0x02000404L,0x00002404L,0x02002404L, - 0x00200404L,0x02200404L,0x00202404L,0x02202404L, - 0x10000000L,0x12000000L,0x10002000L,0x12002000L, - 0x10200000L,0x12200000L,0x10202000L,0x12202000L, - 0x10000004L,0x12000004L,0x10002004L,0x12002004L, - 0x10200004L,0x12200004L,0x10202004L,0x12202004L, - 0x10000400L,0x12000400L,0x10002400L,0x12002400L, - 0x10200400L,0x12200400L,0x10202400L,0x12202400L, - 0x10000404L,0x12000404L,0x10002404L,0x12002404L, - 0x10200404L,0x12200404L,0x10202404L,0x12202404L, + 0x00000000L, 0x02000000L, 0x00002000L, 0x02002000L, + 0x00200000L, 0x02200000L, 0x00202000L, 0x02202000L, + 0x00000004L, 0x02000004L, 0x00002004L, 0x02002004L, + 0x00200004L, 0x02200004L, 0x00202004L, 0x02202004L, + 0x00000400L, 0x02000400L, 0x00002400L, 0x02002400L, + 0x00200400L, 0x02200400L, 0x00202400L, 0x02202400L, + 0x00000404L, 0x02000404L, 0x00002404L, 0x02002404L, + 0x00200404L, 0x02200404L, 0x00202404L, 0x02202404L, + 0x10000000L, 0x12000000L, 0x10002000L, 0x12002000L, + 0x10200000L, 0x12200000L, 0x10202000L, 0x12202000L, + 0x10000004L, 0x12000004L, 0x10002004L, 0x12002004L, + 0x10200004L, 0x12200004L, 0x10202004L, 0x12202004L, + 0x10000400L, 0x12000400L, 0x10002400L, 0x12002400L, + 0x10200400L, 0x12200400L, 0x10202400L, 0x12202400L, + 0x10000404L, 0x12000404L, 0x10002404L, 0x12002404L, + 0x10200404L, 0x12200404L, 0x10202404L, 0x12202404L, }, { /* for C bits (numbered as per FIPS 46) 14 15 16 17 19 20 */ - 0x00000000L,0x00000001L,0x00040000L,0x00040001L, - 0x01000000L,0x01000001L,0x01040000L,0x01040001L, - 0x00000002L,0x00000003L,0x00040002L,0x00040003L, - 0x01000002L,0x01000003L,0x01040002L,0x01040003L, - 0x00000200L,0x00000201L,0x00040200L,0x00040201L, - 0x01000200L,0x01000201L,0x01040200L,0x01040201L, - 0x00000202L,0x00000203L,0x00040202L,0x00040203L, - 0x01000202L,0x01000203L,0x01040202L,0x01040203L, - 0x08000000L,0x08000001L,0x08040000L,0x08040001L, - 0x09000000L,0x09000001L,0x09040000L,0x09040001L, - 0x08000002L,0x08000003L,0x08040002L,0x08040003L, - 0x09000002L,0x09000003L,0x09040002L,0x09040003L, - 0x08000200L,0x08000201L,0x08040200L,0x08040201L, - 0x09000200L,0x09000201L,0x09040200L,0x09040201L, - 0x08000202L,0x08000203L,0x08040202L,0x08040203L, - 0x09000202L,0x09000203L,0x09040202L,0x09040203L, + 0x00000000L, 0x00000001L, 0x00040000L, 0x00040001L, + 0x01000000L, 0x01000001L, 0x01040000L, 0x01040001L, + 0x00000002L, 0x00000003L, 0x00040002L, 0x00040003L, + 0x01000002L, 0x01000003L, 0x01040002L, 0x01040003L, + 0x00000200L, 0x00000201L, 0x00040200L, 0x00040201L, + 0x01000200L, 0x01000201L, 0x01040200L, 0x01040201L, + 0x00000202L, 0x00000203L, 0x00040202L, 0x00040203L, + 0x01000202L, 0x01000203L, 0x01040202L, 0x01040203L, + 0x08000000L, 0x08000001L, 0x08040000L, 0x08040001L, + 0x09000000L, 0x09000001L, 0x09040000L, 0x09040001L, + 0x08000002L, 0x08000003L, 0x08040002L, 0x08040003L, + 0x09000002L, 0x09000003L, 0x09040002L, 0x09040003L, + 0x08000200L, 0x08000201L, 0x08040200L, 0x08040201L, + 0x09000200L, 0x09000201L, 0x09040200L, 0x09040201L, + 0x08000202L, 0x08000203L, 0x08040202L, 0x08040203L, + 0x09000202L, 0x09000203L, 0x09040202L, 0x09040203L, }, { /* for C bits (numbered as per FIPS 46) 21 23 24 26 27 28 */ - 0x00000000L,0x00100000L,0x00000100L,0x00100100L, - 0x00000008L,0x00100008L,0x00000108L,0x00100108L, - 0x00001000L,0x00101000L,0x00001100L,0x00101100L, - 0x00001008L,0x00101008L,0x00001108L,0x00101108L, - 0x04000000L,0x04100000L,0x04000100L,0x04100100L, - 0x04000008L,0x04100008L,0x04000108L,0x04100108L, - 0x04001000L,0x04101000L,0x04001100L,0x04101100L, - 0x04001008L,0x04101008L,0x04001108L,0x04101108L, - 0x00020000L,0x00120000L,0x00020100L,0x00120100L, - 0x00020008L,0x00120008L,0x00020108L,0x00120108L, - 0x00021000L,0x00121000L,0x00021100L,0x00121100L, - 0x00021008L,0x00121008L,0x00021108L,0x00121108L, - 0x04020000L,0x04120000L,0x04020100L,0x04120100L, - 0x04020008L,0x04120008L,0x04020108L,0x04120108L, - 0x04021000L,0x04121000L,0x04021100L,0x04121100L, - 0x04021008L,0x04121008L,0x04021108L,0x04121108L, + 0x00000000L, 0x00100000L, 0x00000100L, 0x00100100L, + 0x00000008L, 0x00100008L, 0x00000108L, 0x00100108L, + 0x00001000L, 0x00101000L, 0x00001100L, 0x00101100L, + 0x00001008L, 0x00101008L, 0x00001108L, 0x00101108L, + 0x04000000L, 0x04100000L, 0x04000100L, 0x04100100L, + 0x04000008L, 0x04100008L, 0x04000108L, 0x04100108L, + 0x04001000L, 0x04101000L, 0x04001100L, 0x04101100L, + 0x04001008L, 0x04101008L, 0x04001108L, 0x04101108L, + 0x00020000L, 0x00120000L, 0x00020100L, 0x00120100L, + 0x00020008L, 0x00120008L, 0x00020108L, 0x00120108L, + 0x00021000L, 0x00121000L, 0x00021100L, 0x00121100L, + 0x00021008L, 0x00121008L, 0x00021108L, 0x00121108L, + 0x04020000L, 0x04120000L, 0x04020100L, 0x04120100L, + 0x04020008L, 0x04120008L, 0x04020108L, 0x04120108L, + 0x04021000L, 0x04121000L, 0x04021100L, 0x04121100L, + 0x04021008L, 0x04121008L, 0x04021108L, 0x04121108L, }, { /* for D bits (numbered as per FIPS 46) 1 2 3 4 5 6 */ - 0x00000000L,0x10000000L,0x00010000L,0x10010000L, - 0x00000004L,0x10000004L,0x00010004L,0x10010004L, - 0x20000000L,0x30000000L,0x20010000L,0x30010000L, - 0x20000004L,0x30000004L,0x20010004L,0x30010004L, - 0x00100000L,0x10100000L,0x00110000L,0x10110000L, - 0x00100004L,0x10100004L,0x00110004L,0x10110004L, - 0x20100000L,0x30100000L,0x20110000L,0x30110000L, - 0x20100004L,0x30100004L,0x20110004L,0x30110004L, - 0x00001000L,0x10001000L,0x00011000L,0x10011000L, - 0x00001004L,0x10001004L,0x00011004L,0x10011004L, - 0x20001000L,0x30001000L,0x20011000L,0x30011000L, - 0x20001004L,0x30001004L,0x20011004L,0x30011004L, - 0x00101000L,0x10101000L,0x00111000L,0x10111000L, - 0x00101004L,0x10101004L,0x00111004L,0x10111004L, - 0x20101000L,0x30101000L,0x20111000L,0x30111000L, - 0x20101004L,0x30101004L,0x20111004L,0x30111004L, + 0x00000000L, 0x10000000L, 0x00010000L, 0x10010000L, + 0x00000004L, 0x10000004L, 0x00010004L, 0x10010004L, + 0x20000000L, 0x30000000L, 0x20010000L, 0x30010000L, + 0x20000004L, 0x30000004L, 0x20010004L, 0x30010004L, + 0x00100000L, 0x10100000L, 0x00110000L, 0x10110000L, + 0x00100004L, 0x10100004L, 0x00110004L, 0x10110004L, + 0x20100000L, 0x30100000L, 0x20110000L, 0x30110000L, + 0x20100004L, 0x30100004L, 0x20110004L, 0x30110004L, + 0x00001000L, 0x10001000L, 0x00011000L, 0x10011000L, + 0x00001004L, 0x10001004L, 0x00011004L, 0x10011004L, + 0x20001000L, 0x30001000L, 0x20011000L, 0x30011000L, + 0x20001004L, 0x30001004L, 0x20011004L, 0x30011004L, + 0x00101000L, 0x10101000L, 0x00111000L, 0x10111000L, + 0x00101004L, 0x10101004L, 0x00111004L, 0x10111004L, + 0x20101000L, 0x30101000L, 0x20111000L, 0x30111000L, + 0x20101004L, 0x30101004L, 0x20111004L, 0x30111004L, }, { /* for D bits (numbered as per FIPS 46) 8 9 11 12 13 14 */ - 0x00000000L,0x08000000L,0x00000008L,0x08000008L, - 0x00000400L,0x08000400L,0x00000408L,0x08000408L, - 0x00020000L,0x08020000L,0x00020008L,0x08020008L, - 0x00020400L,0x08020400L,0x00020408L,0x08020408L, - 0x00000001L,0x08000001L,0x00000009L,0x08000009L, - 0x00000401L,0x08000401L,0x00000409L,0x08000409L, - 0x00020001L,0x08020001L,0x00020009L,0x08020009L, - 0x00020401L,0x08020401L,0x00020409L,0x08020409L, - 0x02000000L,0x0A000000L,0x02000008L,0x0A000008L, - 0x02000400L,0x0A000400L,0x02000408L,0x0A000408L, - 0x02020000L,0x0A020000L,0x02020008L,0x0A020008L, - 0x02020400L,0x0A020400L,0x02020408L,0x0A020408L, - 0x02000001L,0x0A000001L,0x02000009L,0x0A000009L, - 0x02000401L,0x0A000401L,0x02000409L,0x0A000409L, - 0x02020001L,0x0A020001L,0x02020009L,0x0A020009L, - 0x02020401L,0x0A020401L,0x02020409L,0x0A020409L, + 0x00000000L, 0x08000000L, 0x00000008L, 0x08000008L, + 0x00000400L, 0x08000400L, 0x00000408L, 0x08000408L, + 0x00020000L, 0x08020000L, 0x00020008L, 0x08020008L, + 0x00020400L, 0x08020400L, 0x00020408L, 0x08020408L, + 0x00000001L, 0x08000001L, 0x00000009L, 0x08000009L, + 0x00000401L, 0x08000401L, 0x00000409L, 0x08000409L, + 0x00020001L, 0x08020001L, 0x00020009L, 0x08020009L, + 0x00020401L, 0x08020401L, 0x00020409L, 0x08020409L, + 0x02000000L, 0x0A000000L, 0x02000008L, 0x0A000008L, + 0x02000400L, 0x0A000400L, 0x02000408L, 0x0A000408L, + 0x02020000L, 0x0A020000L, 0x02020008L, 0x0A020008L, + 0x02020400L, 0x0A020400L, 0x02020408L, 0x0A020408L, + 0x02000001L, 0x0A000001L, 0x02000009L, 0x0A000009L, + 0x02000401L, 0x0A000401L, 0x02000409L, 0x0A000409L, + 0x02020001L, 0x0A020001L, 0x02020009L, 0x0A020009L, + 0x02020401L, 0x0A020401L, 0x02020409L, 0x0A020409L, }, { /* for D bits (numbered as per FIPS 46) 16 17 18 19 20 21 */ - 0x00000000L,0x00000100L,0x00080000L,0x00080100L, - 0x01000000L,0x01000100L,0x01080000L,0x01080100L, - 0x00000010L,0x00000110L,0x00080010L,0x00080110L, - 0x01000010L,0x01000110L,0x01080010L,0x01080110L, - 0x00200000L,0x00200100L,0x00280000L,0x00280100L, - 0x01200000L,0x01200100L,0x01280000L,0x01280100L, - 0x00200010L,0x00200110L,0x00280010L,0x00280110L, - 0x01200010L,0x01200110L,0x01280010L,0x01280110L, - 0x00000200L,0x00000300L,0x00080200L,0x00080300L, - 0x01000200L,0x01000300L,0x01080200L,0x01080300L, - 0x00000210L,0x00000310L,0x00080210L,0x00080310L, - 0x01000210L,0x01000310L,0x01080210L,0x01080310L, - 0x00200200L,0x00200300L,0x00280200L,0x00280300L, - 0x01200200L,0x01200300L,0x01280200L,0x01280300L, - 0x00200210L,0x00200310L,0x00280210L,0x00280310L, - 0x01200210L,0x01200310L,0x01280210L,0x01280310L, + 0x00000000L, 0x00000100L, 0x00080000L, 0x00080100L, + 0x01000000L, 0x01000100L, 0x01080000L, 0x01080100L, + 0x00000010L, 0x00000110L, 0x00080010L, 0x00080110L, + 0x01000010L, 0x01000110L, 0x01080010L, 0x01080110L, + 0x00200000L, 0x00200100L, 0x00280000L, 0x00280100L, + 0x01200000L, 0x01200100L, 0x01280000L, 0x01280100L, + 0x00200010L, 0x00200110L, 0x00280010L, 0x00280110L, + 0x01200010L, 0x01200110L, 0x01280010L, 0x01280110L, + 0x00000200L, 0x00000300L, 0x00080200L, 0x00080300L, + 0x01000200L, 0x01000300L, 0x01080200L, 0x01080300L, + 0x00000210L, 0x00000310L, 0x00080210L, 0x00080310L, + 0x01000210L, 0x01000310L, 0x01080210L, 0x01080310L, + 0x00200200L, 0x00200300L, 0x00280200L, 0x00280300L, + 0x01200200L, 0x01200300L, 0x01280200L, 0x01280300L, + 0x00200210L, 0x00200310L, 0x00280210L, 0x00280310L, + 0x01200210L, 0x01200310L, 0x01280210L, 0x01280310L, }, { /* for D bits (numbered as per FIPS 46) 22 23 24 25 27 28 */ - 0x00000000L,0x04000000L,0x00040000L,0x04040000L, - 0x00000002L,0x04000002L,0x00040002L,0x04040002L, - 0x00002000L,0x04002000L,0x00042000L,0x04042000L, - 0x00002002L,0x04002002L,0x00042002L,0x04042002L, - 0x00000020L,0x04000020L,0x00040020L,0x04040020L, - 0x00000022L,0x04000022L,0x00040022L,0x04040022L, - 0x00002020L,0x04002020L,0x00042020L,0x04042020L, - 0x00002022L,0x04002022L,0x00042022L,0x04042022L, - 0x00000800L,0x04000800L,0x00040800L,0x04040800L, - 0x00000802L,0x04000802L,0x00040802L,0x04040802L, - 0x00002800L,0x04002800L,0x00042800L,0x04042800L, - 0x00002802L,0x04002802L,0x00042802L,0x04042802L, - 0x00000820L,0x04000820L,0x00040820L,0x04040820L, - 0x00000822L,0x04000822L,0x00040822L,0x04040822L, - 0x00002820L,0x04002820L,0x00042820L,0x04042820L, - 0x00002822L,0x04002822L,0x00042822L,0x04042822L, + 0x00000000L, 0x04000000L, 0x00040000L, 0x04040000L, + 0x00000002L, 0x04000002L, 0x00040002L, 0x04040002L, + 0x00002000L, 0x04002000L, 0x00042000L, 0x04042000L, + 0x00002002L, 0x04002002L, 0x00042002L, 0x04042002L, + 0x00000020L, 0x04000020L, 0x00040020L, 0x04040020L, + 0x00000022L, 0x04000022L, 0x00040022L, 0x04040022L, + 0x00002020L, 0x04002020L, 0x00042020L, 0x04042020L, + 0x00002022L, 0x04002022L, 0x00042022L, 0x04042022L, + 0x00000800L, 0x04000800L, 0x00040800L, 0x04040800L, + 0x00000802L, 0x04000802L, 0x00040802L, 0x04040802L, + 0x00002800L, 0x04002800L, 0x00042800L, 0x04042800L, + 0x00002802L, 0x04002802L, 0x00042802L, 0x04042802L, + 0x00000820L, 0x04000820L, 0x00040820L, 0x04040820L, + 0x00000822L, 0x04000822L, 0x00040822L, 0x04040822L, + 0x00002820L, 0x04002820L, 0x00042820L, 0x04042820L, + 0x00002822L, 0x04002822L, 0x00042822L, 0x04042822L, } }; @@ -419,4 +419,4 @@ int SDRM_DES64_Decryption(cc_u8 *plainText, cc_u8 *cipherText, cc_u8 *UserKey); #endif -/***************************** End of File *****************************/ \ No newline at end of file +/***************************** End of File *****************************/ diff --git a/ssflib/dep/cryptocore/include/base/cc_ecc.h b/ssflib/dep/cryptocore/include/base/cc_ecc.h index 5cb9683..c09bd34 100644 --- a/ssflib/dep/cryptocore/include/base/cc_ecc.h +++ b/ssflib/dep/cryptocore/include/base/cc_ecc.h @@ -50,7 +50,7 @@ A->z = SDRM_BN_Alloc((cc_u8*)A->y + SDRM_ECC_ALLOC_SIZE, SDRM_ECC_BN_BUFSIZE); \ A->z2 = SDRM_BN_Alloc((cc_u8*)A->z + SDRM_ECC_ALLOC_SIZE, SDRM_ECC_BN_BUFSIZE); \ A->z3 = SDRM_BN_Alloc((cc_u8*)A->z2 + SDRM_ECC_ALLOC_SIZE, SDRM_ECC_BN_BUFSIZE); \ - } while(0) + } while (0) #define SDRM_EC_CLR(A) SDRM_EC_SET_ZERO(A) @@ -62,7 +62,7 @@ SDRM_BN_Clr((A)->PRIV_KEY); \ EC_Clr((A)->ECC_G); \ EC_Clr((A)->PUBLIC_KEY); \ - } while(0) + } while (0) #define SDRM_ECC_FREE(X) do { \ if ((X)) { \ @@ -71,7 +71,7 @@ SDRM_EC_FREE(X->PUBLIC_KEY); \ SDRM_EC_FREE(X); \ } \ - } while(0) + } while (0) #define SDRM_EC_COPY(A, B) do { \ (A)->IsInfinity = (B)->IsInfinity; \ @@ -80,7 +80,7 @@ SDRM_BN_Copy((A)->z, (B)->z); \ SDRM_BN_Copy((A)->z2, (B)->z2); \ SDRM_BN_Copy((A)->z3, (B)->z3); \ - } while(0) + } while (0) //////////////////////////////////////////////////////////////////////////// diff --git a/ssflib/dep/cryptocore/include/base/cc_fast_math.h b/ssflib/dep/cryptocore/include/base/cc_fast_math.h index 7654f11..cc6e74c 100644 --- a/ssflib/dep/cryptocore/include/base/cc_fast_math.h +++ b/ssflib/dep/cryptocore/include/base/cc_fast_math.h @@ -69,13 +69,13 @@ typedef cc_u64 BasicDWord; /* If for some reasons it isn't so, then we just need to redefine rhe following two macros in appropriate way * and functions will work properly. */ -#define _add_add_(aw1,aw2,aw3,rwl,rwh) { \ +#define _add_add_(aw1, aw2, aw3, rwl, rwh) { \ BasicDWord dw = (BasicDWord)(aw1)+(aw2)+(aw3); \ rwl = LOW_WORD(dw); \ rwh = HIGH_WORD(dw); \ } -#define _mul_add_add(wm1,wm2,aw1,aw2,rwl,rwh) { \ +#define _mul_add_add(wm1, wm2, aw1, aw2, rwl, rwh) { \ BasicDWord dw = (BasicDWord)(wm1)*(wm2)+(aw1)+(aw2); \ rwl = LOW_WORD(dw); \ rwh = HIGH_WORD(dw); \ @@ -284,7 +284,7 @@ int SDRM_ll_mont_Mul(IN BasicWord *pFirstOperand, * @warning [Optional] constraints or notices * @see [Optional] related information */ -int SDRM_ll_ExpMod( IN BasicWord *pBase, IN BasicWord uBaseLengthInBytes, +int SDRM_ll_ExpMod(IN BasicWord *pBase, IN BasicWord uBaseLengthInBytes, IN BasicWord *pExponent, IN BasicWord uExponentLengthInBytes, IN BasicWord *pModule, IN BasicWord uModuleLengthInBytes, OUT BasicWord *pResult); diff --git a/ssflib/dep/cryptocore/include/base/cc_md5.h b/ssflib/dep/cryptocore/include/base/cc_md5.h index d4ef63d..73015ab 100644 --- a/ssflib/dep/cryptocore/include/base/cc_md5.h +++ b/ssflib/dep/cryptocore/include/base/cc_md5.h @@ -40,7 +40,7 @@ void SDRM_MD5_Init(SDRM_MD5Context *ctx); void SDRM_MD5_Update(SDRM_MD5Context *ctx, cc_u8* buffer, cc_u32 cc_u8Count); -void SDRM_MD5_Final(SDRM_MD5Context *ctx, cc_u8* output ); +void SDRM_MD5_Final(SDRM_MD5Context *ctx, cc_u8* output); #ifdef __cplusplus } @@ -48,4 +48,4 @@ void SDRM_MD5_Final(SDRM_MD5Context *ctx, cc_u8* output ); #endif // _MD5_H -/***************************** End of File *****************************/ \ No newline at end of file +/***************************** End of File *****************************/ diff --git a/ssflib/dep/cryptocore/include/base/cc_moo.h b/ssflib/dep/cryptocore/include/base/cc_moo.h index 9bbecd5..ae2559a 100644 --- a/ssflib/dep/cryptocore/include/base/cc_moo.h +++ b/ssflib/dep/cryptocore/include/base/cc_moo.h @@ -39,7 +39,7 @@ //////////////////////////////////////////////////////////////////////////// #ifndef SDRM_CheckByteUINT32 /*! @brief get k-th byte from cc_u32 array A */ -#define SDRM_CheckByteUINT32(A, k) (cc_u8)(0xff & (A[(k) >> 2] >> (((k) & 3 ) << 3))) +#define SDRM_CheckByteUINT32(A, k) (cc_u8)(0xff & (A[(k) >> 2] >> (((k) & 3) << 3))) #endif diff --git a/ssflib/dep/cryptocore/include/drm_macro.h b/ssflib/dep/cryptocore/include/drm_macro.h index 89629dd..8cdf1a5 100644 --- a/ssflib/dep/cryptocore/include/drm_macro.h +++ b/ssflib/dep/cryptocore/include/drm_macro.h @@ -43,8 +43,8 @@ #define PrintBYTE(msg, Data, DataLen) { \ int idx; \ printf("%10s =", msg); \ - for( idx=0; idx<(int)DataLen; idx++) { \ - if( (idx!=0) && ((idx%16)==0) ) printf("\n"); \ + for( idx = 0; idx < (int)DataLen; idx++) { \ + if( (idx != 0) && ((idx%16) == 0) ) printf("\n"); \ if((idx % 4) == 0) printf(" 0x"); \ printf("%.2x", Data[idx]); \ } \ @@ -56,8 +56,8 @@ #define PrintBYTE_HEX(msg, Data, DataLen) { \ int idx; \ printf("%10s =", msg); \ - for( idx=0; idx<(int)DataLen; idx++) { \ - if( (idx!=0) && ((idx%8)==0) ) printf("\n"); \ + for( idx = 0; idx < (int)DataLen; idx++) { \ + if( (idx != 0) && ((idx%8) == 0) ) printf("\n"); \ printf("0x%.2x, ", Data[idx]); \ } \ printf("\n"); \ @@ -67,8 +67,8 @@ #undef PrintBYTE_FILE_RAW // raw data ���·� ����� �� �ֵ��� Hex ���·� ��� #define PrintBYTE_FILE_RAW(pfile, Data, DataLen) { \ int idx; \ - for( idx=0; idx<(int)DataLen; idx++) { \ - if( (idx==0) || ((idx%8)!=0) ) \ + for( idx = 0; idx < (int)DataLen; idx++) { \ + if( (idx == 0) || ((idx%8) != 0) ) \ fprintf(pfile, "0x%.2x, ", Data[idx]); \ else \ fprintf(pfile, " \n0x%.2x, ", Data[idx]); \ @@ -99,7 +99,7 @@ /*! @brief convert 32-bit unit to 4 byte */ #undef GET_UINT32 -#define GET_UINT32(n,b,i) \ +#define GET_UINT32(n, b, i) \ { \ (n) = ((unsigned int)((b)[(i) ]) << 24 ) \ | ((unsigned int)((b)[(i) + 1]) << 16 ) \ @@ -109,7 +109,7 @@ /*! @brief 4 byte to 32-bit unit */ #undef PUT_UINT32 -#define PUT_UINT32(n,b,i) \ +#define PUT_UINT32(n, b, i) \ { \ (b)[(i) ] = (unsigned char) ( (n) >> 24 ); \ (b)[(i) + 1] = (unsigned char) ( (n) >> 16 ); \ @@ -119,7 +119,7 @@ /*! @brief convert 24-bit unit to 3 byte */ #undef GET_UINT24 -#define GET_UINT24(n,b,i) \ +#define GET_UINT24(n, b, i) \ { \ (n) = ( (b)[(i) ] << 16 ) \ | ( (b)[(i) + 1] << 8 ) \ @@ -128,7 +128,7 @@ /*! @brief convert 3 byte to 24-bit unit */ #undef PUT_UINT24 -#define PUT_UINT24(n,b,i) \ +#define PUT_UINT24(n, b, i) \ { \ (b)[(i) ] = (unsigned char) ( (n) >> 16 ); \ (b)[(i) + 1] = (unsigned char) ( (n) >> 8 ); \ @@ -137,7 +137,7 @@ /*! @brief convert 16-bit unit to 2 byte */ #undef GET_UINT16 -#define GET_UINT16(n,b,i) \ +#define GET_UINT16(n, b, i) \ { \ (n) = ( (b)[(i) ] << 8 ) \ | ( (b)[(i) + 1] ); \ @@ -145,7 +145,7 @@ /*! @brief convert 2 byte to 16-bit unit */ #undef PUT_UINT16 -#define PUT_UINT16(n,b,i) \ +#define PUT_UINT16(n, b, i) \ { \ (b)[(i) ] = (unsigned char) ( (n) >> 8 ); \ (b)[(i) + 1] = (unsigned char) ( (n) ); \ @@ -153,60 +153,60 @@ /*! @brief read 1 byte of s form o & increase o */ #undef READ_8 -#define READ_8(t,s,o) { \ +#define READ_8(t, s, o) { \ t = (unsigned char) s[o]; \ o+=1; \ } /*! @brief read 2 byte of sfrom o & increase o */ #undef READ_16 -#define READ_16(t,s,o) { \ - GET_UINT16(t,s,o); \ +#define READ_16(t, s, o) { \ + GET_UINT16(t, s, o); \ o+=2; \ } /*! @brief read 3 byte of s from o & increase o */ #undef READ_24 -#define READ_24(t,s,o) { \ - GET_UINT24(t,s,o); \ +#define READ_24(t, s, o) { \ + GET_UINT24(t, s, o); \ o+=3; \ } /*! @brief read 4 byte of s from o & increase o */ #undef READ_32 -#define READ_32(t,s,o) { \ - GET_UINT32(t,s,o); \ +#define READ_32(t, s, o) { \ + GET_UINT32(t, s, o); \ o+=4; \ } /*! @brief write 4 byte to s from o & increase o */ #undef WRITE_32 -#define WRITE_32(t,s,o) { \ - PUT_UINT32(s,t,o); \ +#define WRITE_32(t, s, o) { \ + PUT_UINT32(s, t, o); \ o+=4; \ } /*! @brief write 3 byte to s from o & increase o */ #undef WRITE_24 -#define WRITE_24(t,s,o) { \ - PUT_UINT24(s,t,o); \ +#define WRITE_24(t, s, o) { \ + PUT_UINT24(s, t, o); \ o+=3; \ } /*! @brief write 2 byte to s from o & increase o */ #undef WRITE_16 -#define WRITE_16(t,s,o) { \ - PUT_UINT16(s,t,o); \ +#define WRITE_16(t, s, o) { \ + PUT_UINT16(s, t, o); \ o+=2; \ } /*! @brief write 1 byte to s from o & increase o */ #undef WRITE_8 -#define WRITE_8(t,s,o) { \ +#define WRITE_8(t, s, o) { \ t[o] = (unsigned char)s; \ o+=1; \ } #endif -/***************************** End of File *****************************/ \ No newline at end of file +/***************************** End of File *****************************/ diff --git a/ssflib/dep/swdss/include/file_op.h b/ssflib/dep/swdss/include/file_op.h index ad5db6e..0e45b69 100644 --- a/ssflib/dep/swdss/include/file_op.h +++ b/ssflib/dep/swdss/include/file_op.h @@ -111,7 +111,6 @@ public: * @return base path */ static void get_base_path(const char* filename, char* base_path); - }; #endif diff --git a/ssflib/dep/swdss/include/secure_file.h b/ssflib/dep/swdss/include/secure_file.h index 1e57a1e..183a1c4 100644 --- a/ssflib/dep/swdss/include/secure_file.h +++ b/ssflib/dep/swdss/include/secure_file.h @@ -295,7 +295,6 @@ private: unsigned int m_read_data_size; bool m_file_path_ready; - }; #endif diff --git a/ssflib/dep/swdss/include/ss_types.h b/ssflib/dep/swdss/include/ss_types.h index 3200df7..4295bcb 100644 --- a/ssflib/dep/swdss/include/ss_types.h +++ b/ssflib/dep/swdss/include/ss_types.h @@ -84,7 +84,6 @@ typedef struct credential { unsigned long major; unsigned long minor; } version; /**< module version.*/ - } ss_credential_s; typedef uint8_t CBT_OCTET; diff --git a/ssflib/dep/swdss/source/file_op.cpp b/ssflib/dep/swdss/source/file_op.cpp index eafe680..c731bd0 100644 --- a/ssflib/dep/swdss/source/file_op.cpp +++ b/ssflib/dep/swdss/source/file_op.cpp @@ -111,7 +111,7 @@ int file_op::read_file(const char* filename, unsigned char** buffer, if (fLen > 0) { size = fLen; } - if( fseek(file, 0, SEEK_SET) != 0){ + if (fseek(file, 0, SEEK_SET) != 0){ fclose(file); return SS_RET_FAIL; } diff --git a/ssflib/dep/swdss/source/ss_crypto.cpp b/ssflib/dep/swdss/source/ss_crypto.cpp index ba7b0f7..d4c5e99 100644 --- a/ssflib/dep/swdss/source/ss_crypto.cpp +++ b/ssflib/dep/swdss/source/ss_crypto.cpp @@ -112,7 +112,7 @@ int CCryptoEngine::HWEncrypt(unsigned char* dest, unsigned long* dest_len, #else UCI_HANDLE uh = UCI_ERROR; - uh = uci_context_alloc(ID_UCI_AES128,(uci_engine_config_e)key_type); + uh = uci_context_alloc(ID_UCI_AES128, (uci_engine_config_e)key_type); if ((UCI_ERROR == uh) || (UCI_MEM_ALLOR_ERROR == uh)) { SLOGE("Failed to alloc uci context handle.\n"); @@ -125,17 +125,17 @@ int CCryptoEngine::HWEncrypt(unsigned char* dest, unsigned long* dest_len, { case ID_UCI_ENC_CTR: { - ret = uci_se_init(uh,ID_UCI_ENC_CTR,ID_UCI_NO_PADDING,(unsigned char*)key,16,NULL); + ret = uci_se_init(uh, ID_UCI_ENC_CTR, ID_UCI_NO_PADDING, (unsigned char*)key, 16, NULL); break; } case ID_UCI_ENC_ECB: { - ret = uci_se_init(uh,ID_UCI_ENC_ECB,ID_UCI_PKCS5,(unsigned char*)key,16,NULL); + ret = uci_se_init(uh, ID_UCI_ENC_ECB, ID_UCI_PKCS5, (unsigned char*)key, 16, NULL); break; } default: { - SLOGE("Mode %d not supported.",mode); + SLOGE("Mode %d not supported.", mode); uci_context_free(uh); return SS_RET_INVALID_PARAM; } @@ -143,24 +143,24 @@ int CCryptoEngine::HWEncrypt(unsigned char* dest, unsigned long* dest_len, if (UCI_SUCCESS != ret) { - SLOGE("Failed to init context, retcode = %d.\n",ret); + SLOGE("Failed to init context, retcode = %d.\n", ret); uci_context_free(uh); return SS_RET_FAIL; } - ret = uci_se_process(uh,src,data_len,dest,(unsigned int*)dest_len); + ret = uci_se_process(uh, src, data_len, dest, (unsigned int*)dest_len); if (UCI_SUCCESS != ret) { - SLOGE("Failed to encrypt data, retcode = %d.\n",ret); + SLOGE("Failed to encrypt data, retcode = %d.\n", ret); uci_context_free(uh); return SS_RET_FAIL; } unsigned int t; - ret = uci_se_final(uh,NULL,0,dest+(*dest_len),&t); + ret = uci_se_final(uh, NULL, 0, dest+(*dest_len), &t); if (UCI_SUCCESS != ret) { - SLOGE("Failed to call uci_se_final, retcode = %d.\n",ret); + SLOGE("Failed to call uci_se_final, retcode = %d.\n", ret); uci_context_free(uh); return SS_RET_FAIL; } @@ -170,7 +170,7 @@ int CCryptoEngine::HWEncrypt(unsigned char* dest, unsigned long* dest_len, ret = uci_context_free(uh); if (UCI_SUCCESS != ret) { - SLOGE("Failed to free context, retcode = %d.\n",ret); + SLOGE("Failed to free context, retcode = %d.\n", ret); } return SS_RET_SUCCESS; @@ -185,7 +185,7 @@ int CCryptoEngine::HWDecrypt(unsigned char* dest, unsigned long* dest_len, unsigned long key_type, unsigned long mode) { #if !defined(_SECOS_SIM_) UCI_HANDLE uh = UCI_ERROR; - uh = uci_context_alloc(ID_UCI_AES128,(uci_engine_config_e)key_type); + uh = uci_context_alloc(ID_UCI_AES128, (uci_engine_config_e)key_type); if ((UCI_ERROR == uh) || (UCI_MEM_ALLOR_ERROR == uh)) { SLOGE("Failed to alloc uci context handle."); @@ -198,41 +198,41 @@ int CCryptoEngine::HWDecrypt(unsigned char* dest, unsigned long* dest_len, { case ID_UCI_ENC_CTR: { - ret = uci_se_init(uh,ID_UCI_DEC_CTR,ID_UCI_NO_PADDING,(unsigned char*)key,16,NULL); + ret = uci_se_init(uh, ID_UCI_DEC_CTR, ID_UCI_NO_PADDING, (unsigned char*)key, 16, NULL); break; } case ID_UCI_ENC_ECB: { - ret = uci_se_init(uh,ID_UCI_DEC_ECB,ID_UCI_PKCS5,(unsigned char*)key,16,NULL); + ret = uci_se_init(uh, ID_UCI_DEC_ECB, ID_UCI_PKCS5, (unsigned char*)key, 16, NULL); break; } default: { - SLOGE("Mode %d not supported.",mode); + SLOGE("Mode %d not supported.", mode); return SS_RET_INVALID_PARAM; } } if (UCI_SUCCESS != ret) { - SLOGE("Failed to init context, retcode = %d.",ret); + SLOGE("Failed to init context, retcode = %d.", ret); uci_context_free(uh); return SS_RET_FAIL; } - ret = uci_se_process(uh,src,data_len-16,dest,(unsigned int*)dest_len); + ret = uci_se_process(uh, src, data_len-16, dest, (unsigned int*)dest_len); if (UCI_SUCCESS != ret) { - SLOGE("Failed to decrypt data, retcode = %d.",ret); + SLOGE("Failed to decrypt data, retcode = %d.", ret); uci_context_free(uh); return SS_RET_FAIL; } unsigned int t; - ret = uci_se_final(uh,src+data_len-16,16,dest+(*dest_len),&t); + ret = uci_se_final(uh, src+data_len-16, 16, dest+(*dest_len), &t); if (UCI_SUCCESS != ret) { - SLOGE("Failed to call uci_se_final, retcode = %d.",ret); + SLOGE("Failed to call uci_se_final, retcode = %d.", ret); uci_context_free(uh); return SS_RET_FAIL; } @@ -242,7 +242,7 @@ int CCryptoEngine::HWDecrypt(unsigned char* dest, unsigned long* dest_len, ret = uci_context_free(uh); if (UCI_SUCCESS != ret) { - SLOGE("Failed to free context, retcode = %d.",ret); + SLOGE("Failed to free context, retcode = %d.", ret); } return SS_RET_SUCCESS; diff --git a/ssflib/dep/swdss/source/ss_temp_store.cpp b/ssflib/dep/swdss/source/ss_temp_store.cpp index a2d1fde..da48174 100644 --- a/ssflib/dep/swdss/source/ss_temp_store.cpp +++ b/ssflib/dep/swdss/source/ss_temp_store.cpp @@ -19,8 +19,8 @@ #include "slog.h" #include -#define SS_NODE_ID_CMP(id1, id2) memcmp(static_cast(id1),static_cast(id2),SS_NODE_ID_LEN) -#define SS_NODE_ID_CPY(dest,src) memcpy(static_cast(dest),static_cast(src),SS_NODE_ID_LEN) +#define SS_NODE_ID_CMP(id1, id2) memcmp(static_cast(id1), static_cast(id2), SS_NODE_ID_LEN) +#define SS_NODE_ID_CPY(dest, src) memcpy(static_cast(dest), static_cast(src), SS_NODE_ID_LEN) pthread_mutex_t auto_lock::m_mutex = PTHREAD_MUTEX_INITIALIZER; @@ -148,7 +148,6 @@ int ss_temp_store::batch_remove(char* dir) { } return (data_find ? SS_RET_SUCCESS : SS_RET_CANT_FIND_REQUESTED_DATA); - } temp_ss_node* ss_temp_store::find_node(char* data_name) { diff --git a/ssflib/dep/time/ssf_time.cpp b/ssflib/dep/time/ssf_time.cpp index 833fccf..119c511 100644 --- a/ssflib/dep/time/ssf_time.cpp +++ b/ssflib/dep/time/ssf_time.cpp @@ -67,7 +67,8 @@ void TEE_GetSystemTime(TEE_Time* time) { clock_gettime(CLOCK_REALTIME, &tspec); time->seconds = tspec.tv_sec; time->millis = tspec.tv_nsec / 1000000ULL; - } else TEE_GetREETime(time); + } + else TEE_GetREETime(time); } /** diff --git a/ssflib/dep/uci/include/uci_type.h b/ssflib/dep/uci/include/uci_type.h index 74962e7..6ec71a7 100644 --- a/ssflib/dep/uci/include/uci_type.h +++ b/ssflib/dep/uci/include/uci_type.h @@ -198,13 +198,11 @@ enum UCICryptoAlgorithm { /*!\brief Authenticated Encryption Functions */ ID_UCI_AE_GCM = 1091, ID_UCI_AE_CCM = 1092 - }; /** @HW engine key type */ typedef enum { - UCI_USER_KEY = 1, UCI_SECRET_KEY = 2, UCI_MASTER_KEY = 3 } hw_keytype_e; @@ -269,7 +267,6 @@ typedef struct dh_key { unsigned int privatekey_len; unsigned char* publickey; unsigned int publickey_len; - } dh_key_s; /** * @brief imp key union. @@ -318,7 +315,6 @@ typedef struct uci_key { #define ucik_dh_prikey_len imp.dhkey.privatekey_len #define ucik_dh_pubkey imp.dhkey.publickey #define ucik_dh_pubkey_len imp.dhkey.publickey_len - } uci_key_s; typedef enum rsa_kparam_flag { @@ -452,7 +448,6 @@ typedef struct uci_param { #define ucip_dh_prime uparam.udhp.prime #define ucip_dh_generator uparam.udhp.generator #define ucip_dh_len uparam.udhp.len - } uci_param_s; /** @}*/ diff --git a/ssflib/inc/app_debug.h b/ssflib/inc/app_debug.h index d7fed74..f363ba3 100644 --- a/ssflib/inc/app_debug.h +++ b/ssflib/inc/app_debug.h @@ -45,36 +45,36 @@ unsigned char one_time_print_buffer_test[10240]; #define TRUSTAPP_DEBUG_LEVEL_ALL 5 -#define APP_SVC_ERR(title, format,...) do{sprintf(one_time_print_buffer,"[%s][ERR]" format, title,##__VA_ARGS__);\ +#define APP_SVC_ERR(title, format, ...) do{sprintf(one_time_print_buffer, "[%s][ERR]" format, title, ##__VA_ARGS__);\ }while(0); -#define APP_SVC_WRN(title, format,...) do{sprintf(one_time_print_buffer,"[%s][WRN]" format, title,##__VA_ARGS__);\ +#define APP_SVC_WRN(title, format, ...) do{sprintf(one_time_print_buffer, "[%s][WRN]" format, title, ##__VA_ARGS__);\ app_print_log(one_time_print_buffer);\ }while(0); -#define APP_SVC_DBG(title, format,...) do{sprintf(one_time_print_buffer,"[%s][DBG]" format, title,##__VA_ARGS__);\ +#define APP_SVC_DBG(title, format, ...) do{sprintf(one_time_print_buffer, "[%s][DBG]" format, title, ##__VA_ARGS__);\ app_print_log(one_time_print_buffer);\ }while(0); -#define APP_SVC_LOG(title, format,...) do{sprintf((char *)one_time_print_buffer,"[%s][LOG]" format, title,##__VA_ARGS__);\ +#define APP_SVC_LOG(title, format, ...) do{sprintf((char *)one_time_print_buffer, "[%s][LOG]" format, title, ##__VA_ARGS__);\ app_print_log(one_time_print_buffer);\ }while(0); -#define APP_SVC_LOG_test(title, format,...) do{sprintf(()one_time_print_buffer_test,"[%s][LOG]" format, title,##__VA_ARGS__);\ +#define APP_SVC_LOG_test(title, format, ...) do{sprintf(()one_time_print_buffer_test, "[%s][LOG]" format, title, ##__VA_ARGS__);\ app_print_log_test(one_time_print_buffer_test);\ }while(0); -#define TURST_APP_LOG_TEST(fmt,...) {APP_SVC_LOG_test("test", fmt, ##__VA_ARGS__)} +#define TURST_APP_LOG_TEST(fmt, ...) {APP_SVC_LOG_test("test", fmt, ##__VA_ARGS__)} -#define TURST_APP_ERR(fmt, ...) if(g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_ERR) {APP_SVC_ERR(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} -#define TURST_APP_WRN(fmt, ...) if(g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_WRN) {APP_SVC_WRN(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} -#define TURST_APP_DBG(fmt, ...) if(g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_DBG) {APP_SVC_DBG(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} -#define TURST_APP_LOG(fmt, ...) if(g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_LOG) {APP_SVC_LOG(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} +#define TURST_APP_ERR(fmt, ...) if (g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_ERR) {APP_SVC_ERR(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} +#define TURST_APP_WRN(fmt, ...) if (g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_WRN) {APP_SVC_WRN(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} +#define TURST_APP_DBG(fmt, ...) if (g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_DBG) {APP_SVC_DBG(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} +#define TURST_APP_LOG(fmt, ...) if (g_app_svc_dbglvl >= TRUSTAPP_DEBUG_LEVEL_LOG) {APP_SVC_LOG(APP_MODULE_NAME, fmt, ##__VA_ARGS__)} //#define TURST_APP_LOG(fmt, ...) TURST_APP_LOG_TEST(fmt,##__VA_ARGS__) -#define TRACE_FUNCTION_IN TURST_APP_LOG("[%s][%d] In ... \n",__FUNCTION__,__LINE__); -#define TRACE_FUNCTION_OUT TURST_APP_LOG("[%s][%d] Out ... \n",__FUNCTION__,__LINE__); +#define TRACE_FUNCTION_IN TURST_APP_LOG("[%s][%d] In ... \n", __FUNCTION__, __LINE__); +#define TRACE_FUNCTION_OUT TURST_APP_LOG("[%s][%d] Out ... \n", __FUNCTION__, __LINE__); -int app_open_log_file( char *processName); +int app_open_log_file(char *processName); void app_print_log(unsigned char logBuffer[]); void app_close_log_file(void); diff --git a/ssflib/inc/permission.h b/ssflib/inc/permission.h index 4957b18..46c5524 100644 --- a/ssflib/inc/permission.h +++ b/ssflib/inc/permission.h @@ -26,13 +26,13 @@ #include #define PERMISSION_CHECK(variable) \ - if(CheckPermission(variable)) { \ - LOGE(SSF_LIB, "Permission Denied - Function %s() is not permitted." , __FUNCTION__ ); \ + if (CheckPermission(variable)) { \ + LOGE(SSF_LIB, "Permission Denied - Function %s() is not permitted." , __FUNCTION__); \ return TEE_ERROR_ACCESS_DENIED; } #define PERMISSION_CHECK_RETURN_VOID(variable) \ - if(CheckPermission(variable)) { \ - LOGE(SSF_LIB, "Permission Denied - Function %s() is not permitted." , __FUNCTION__ ); \ + if (CheckPermission(variable)) { \ + LOGE(SSF_LIB, "Permission Denied - Function %s() is not permitted." , __FUNCTION__); \ return; } typedef enum { @@ -45,7 +45,7 @@ typedef enum { } ACCESS_PERMISSION; typedef enum { - TA_PRIVILEGE_PUBLIC=1, + TA_PRIVILEGE_PUBLIC = 1, TA_PRIVILEGE_PARTNER, TA_PRIVILEGE_PLATFORM, } TA_PRIVILEGE; diff --git a/ssflib/src/app_debug.cpp b/ssflib/src/app_debug.cpp index 441733d..d169936 100644 --- a/ssflib/src/app_debug.cpp +++ b/ssflib/src/app_debug.cpp @@ -31,34 +31,30 @@ static int m_fd = -1; int g_app_svc_dbglvl = TRUSTAPP_DEBUG_LEVEL_NON; -int app_open_log_file( char *processName) +int app_open_log_file(char *processName) { - /* save log to LOGFILE */ - m_fd = open( portname,O_RDWR | O_NOCTTY | O_NONBLOCK); + m_fd = open(portname, O_RDWR | O_NOCTTY | O_NONBLOCK); if(m_fd < 0) { return -1; } - write(m_fd,processName,strlen(processName)); + write(m_fd, processName, strlen(processName)); - memset(one_time_print_buffer,0,sizeof(one_time_print_buffer)); + memset(one_time_print_buffer, 0, sizeof(one_time_print_buffer)); return 0; - } void app_close_log_file(void) { - close(m_fd); m_fd = -1; } void app_print_log(unsigned char logBuffer[]) { - - write(m_fd,logBuffer,strlen(logBuffer)); + write(m_fd, logBuffer, strlen(logBuffer)); } #else @@ -74,7 +70,6 @@ int g_app_svc_dbglvl = TRUSTAPP_DEBUG_LEVEL_NON; int app_open_log_file(char *processName) { - /* save log to LOGFILE */ fp = fopen(SVC1_LOGFILE, "a+"); if(!fp) @@ -82,31 +77,27 @@ int app_open_log_file(char *processName) return -1; } - fprintf(fp,"Trust App name : %s.\n",processName); + fprintf(fp, "Trust App name : %s.\n", processName); fflush(fp); - memset(one_time_print_buffer,0,sizeof(one_time_print_buffer)); + memset(one_time_print_buffer, 0, sizeof(one_time_print_buffer)); return 0; - } void app_close_log_file(void) { - fclose(fp); fp = NULL; } void app_print_log(unsigned char logBuffer[]) { - - fprintf(fp,"%s",logBuffer); + fprintf(fp, "%s", logBuffer); fflush(fp); } void app_print_log_test(unsigned char logBuffer[]) { - - fprintf(fp,"%s",logBuffer); + fprintf(fp, "%s", logBuffer); fflush(fp); } diff --git a/ssflib/src/ssf_arithmetic.cpp b/ssflib/src/ssf_arithmetic.cpp index 97fc47b..fd4899d 100644 --- a/ssflib/src/ssf_arithmetic.cpp +++ b/ssflib/src/ssf_arithmetic.cpp @@ -49,7 +49,6 @@ * @param length The size in uint32_t of the memory pointed to by bigInt */ void TEE_BigIntInit(TEE_BigInt* value, const size_t length) { - PERMISSION_CHECK_RETURN_VOID(PERM_ARITHMETIC); LOGD(TAG, "TEE_BigIntInit - length : %d", length); uint32_t teeMaxBigIntSize; @@ -270,7 +269,6 @@ bool TEE_BigIntGetBit(const TEE_BigInt* object_raw, const uint32_t index) { bool bitValue = (bool)SDRM_BN_num_bits_index(objBn, index); LOGD(TAG, "Success"); return bitValue; - } /** @@ -342,7 +340,8 @@ void TEE_BigIntNeg(TEE_BigInt* dest, const TEE_BigInt* op) { SDRM_BIG_NUM *bnOp = (SDRM_BIG_NUM*)op; if (dest == op) bnOp->sign = ((bnOp->sign == 1) ? 0 : 1); - else { + else + { SDRM_BIG_NUM *dst = (SDRM_BIG_NUM*)dest; SDRM_BN_Copy(dst, bnOp); dst->sign = ((dst->sign == 1) ? 0 : 1); diff --git a/ssflib/src/ssf_crypto.cpp b/ssflib/src/ssf_crypto.cpp index 4780887..7e4dda3 100644 --- a/ssflib/src/ssf_crypto.cpp +++ b/ssflib/src/ssf_crypto.cpp @@ -47,11 +47,11 @@ int idx; \ printf("%10s =", msg); \ printf("\n"); \ - for( idx=0; idx<(int)DataLen; idx++) { \ - if( (idx!=0) && ((idx%16)==0) ) printf("\n"); \ + for( idx = 0; idx < (int)DataLen; idx++) { \ + if( (idx != 0) && ((idx%16) == 0) ) printf("\n"); \ if((idx % 16) == 0) printf("\t\""); \ printf("%.2X", Data[idx]); \ - if( (idx!=0) && ((idx%16)==15) ) printf("\""); \ + if( (idx != 0) && ((idx%16) == 15) ) printf("\""); \ } \ printf("\n"); \ } @@ -86,66 +86,66 @@ struct __TEE_OperationHandle static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_internal_keystruct *key, unsigned char *ivec, unsigned int ivec_len) { (void)ivec_len; /* actually always==16 */ - int rc=0; + int rc = 0; int mode; - unsigned int padding=ID_NO_PADDING; - CryptoCoreContainer *handle=(CryptoCoreContainer *)operation->crypto; + unsigned int padding = ID_NO_PADDING; + CryptoCoreContainer *handle = (CryptoCoreContainer *)operation->crypto; switch(operation->info.algorithm) { /* TEE_OPERATION_CIPHER */ case TEE_ALG_AES_ECB_NOPAD: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_ECB; - else mode=ID_DEC_ECB; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_ECB; + else mode = ID_DEC_ECB; padding = ID_NO_PADDING; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_ECB_PKCS5: case TEE_ALG_AES_ECB_PKCS7: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_ECB; - else mode=ID_DEC_ECB; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_ECB; + else mode = ID_DEC_ECB; padding = ID_NO_PADDING /* ID_PKCS5 */; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_ECB_ISO9797_M1: case TEE_ALG_AES_ECB_ISO9797_M2: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_ECB; - else mode=ID_DEC_ECB; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_ECB; + else mode = ID_DEC_ECB; padding = ID_NO_PADDING /* ID_PKCS5 */; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_CBC_NOPAD: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_CBC; - else mode=ID_DEC_CBC; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_CBC; + else mode = ID_DEC_CBC; padding = ID_NO_PADDING; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_CBC_PKCS5: case TEE_ALG_AES_CBC_PKCS7: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_CBC; - else mode=ID_DEC_CBC; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_CBC; + else mode = ID_DEC_CBC; padding = ID_NO_PADDING/* ID_PKCS5 */; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_CBC_ISO9797_M1: case TEE_ALG_AES_CBC_ISO9797_M2: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_CBC; - else mode=ID_DEC_CBC; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_CBC; + else mode = ID_DEC_CBC; padding = ID_NO_PADDING /* ID_PKCS5 */; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_CTR: case TEE_ALG_AES_CTR_NOPAD: - if(operation->info.mode == TEE_MODE_ENCRYPT) mode=ID_ENC_CTR; - else mode=ID_DEC_CTR; + if(operation->info.mode == TEE_MODE_ENCRYPT) mode = ID_ENC_CTR; + else mode = ID_DEC_CTR; padding = ID_NO_PADDING; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_AES_CTS: @@ -155,25 +155,23 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_DES_ECB_NOPAD: case TEE_ALG_DES3_ECB_NOPAD: if(operation->info.mode == TEE_MODE_ENCRYPT) { - mode=ID_ENC_ECB; - } - else { - mode=ID_DEC_ECB; + mode = ID_ENC_ECB; + } else { + mode = ID_DEC_ECB; } padding = ID_NO_PADDING; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_DES_CBC_NOPAD: case TEE_ALG_DES3_CBC_NOPAD: if(operation->info.mode == TEE_MODE_ENCRYPT) { - mode=ID_ENC_CBC; - } - else { - mode=ID_DEC_CBC; + mode = ID_ENC_CBC; + } else { + mode = ID_DEC_CBC; } padding = ID_NO_PADDING; - rc=handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); + rc = handle->SE_init(handle, mode, padding, key->secret.buffer, key->secret.size, ivec); break; case TEE_ALG_HMAC_MD5: @@ -189,7 +187,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_AES_CMAC: case TEE_ALG_DES3_CBC_MAC_NOPAD: case TEE_ALG_DES3_CBC_MAC_PKCS5: - rc=handle->MAC_init(handle, key->secret.buffer, key->secret.size); + rc = handle->MAC_init(handle, key->secret.buffer, key->secret.size); break; case TEE_ALG_AES_CCM: @@ -202,12 +200,12 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_SHA256: case TEE_ALG_SHA384: case TEE_ALG_SHA512: - rc=handle->MD_init(handle); + rc = handle->MD_init(handle); break; case TEE_ALG_RSA_NOPAD: padding = ID_NO_PADDING; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -220,7 +218,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSAES_PKCS1_V1_5: padding = ID_RSAES_PKCS15; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -233,7 +231,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA1: padding = ID_RSAES_OAEP_SHA1; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -246,7 +244,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA224: padding = ID_RSAES_OAEP_SHA224; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -259,7 +257,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256: padding = ID_RSAES_OAEP_SHA256; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -272,7 +270,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384: padding = ID_RSAES_OAEP_SHA384; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -285,7 +283,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512: padding = ID_RSAES_OAEP_SHA512; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -298,7 +296,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_V1_5_MD5: padding = ID_RSASSA_PKCS15_MD5; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -311,7 +309,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_V1_5_SHA1: padding = ID_RSASSA_PKCS15_SHA1; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -324,7 +322,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_V1_5_SHA224: padding = ID_RSASSA_PKCS15_SHA224; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -337,7 +335,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_V1_5_SHA256: padding = ID_RSASSA_PKCS15_SHA256; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -350,7 +348,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_V1_5_SHA384: padding = ID_RSASSA_PKCS15_SHA384; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -363,7 +361,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_V1_5_SHA512: padding = ID_RSASSA_PKCS15_SHA512; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -376,7 +374,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA1: padding = ID_RSASSA_PSS_SHA1; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -389,7 +387,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA224: padding = ID_RSASSA_PSS_SHA224; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -402,7 +400,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256: padding = ID_RSASSA_PSS_SHA256; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -415,7 +413,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384: padding = ID_RSASSA_PSS_SHA384; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -428,7 +426,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512: padding = ID_RSASSA_PSS_SHA512; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -441,7 +439,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int case TEE_ALG_DSA_SHA1: padding = 0; - rc=handle->RSA_setKeypairForCRT(handle, padding, + rc = handle->RSA_setKeypairForCRT(handle, padding, key->rsa_modulus.buffer, key->rsa_modulus.size, key->rsa_public.buffer, key->rsa_public.size, key->rsa_private.buffer, key->rsa_private.size, @@ -453,7 +451,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int break; case TEE_ALG_GENERATE_SECRET_KEY: - rc=handle->PRNG_get(handle, key->secret.size, key->secret.buffer); + rc = handle->PRNG_get(handle, key->secret.size, key->secret.buffer); /* Ignore return value to avoid CRYPTO_PANIC. Only SDRM_X931_ConditionalTest() can return TEE_ERROR.*/ rc = TEE_SUCCESS; break; @@ -463,7 +461,7 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int unsigned char E[3] = {0x01, 0x00, 0x01}; unsigned int ELen = 3; - rc=handle->RSA_genKeypairWithEforCRT(handle, padding, + rc = handle->RSA_genKeypairWithEforCRT(handle, padding, E, ELen, key->rsa_modulus.buffer, &key->rsa_modulus.size, key->rsa_private.buffer, &key->rsa_private.size, @@ -493,10 +491,10 @@ static int sw_crypto_ioctl_init(crypto_internal_operation *operation, crypto_int return rc; } -static int sw_crypto_ioctl_update (crypto_internal_operation *operation, unsigned char* src_addr, unsigned int src_size, unsigned char* dst_addr, unsigned int* dst_size) +static int sw_crypto_ioctl_update(crypto_internal_operation *operation, unsigned char* src_addr, unsigned int src_size, unsigned char* dst_addr, unsigned int* dst_size) { int rc; - CryptoCoreContainer *handle=(CryptoCoreContainer *)operation->crypto; + CryptoCoreContainer *handle = (CryptoCoreContainer *)operation->crypto; switch(operation->info.algorithm) { @@ -517,7 +515,7 @@ static int sw_crypto_ioctl_update (crypto_internal_operation *operation, unsigne case TEE_ALG_DES3_ECB_NOPAD: case TEE_ALG_DES_CBC_NOPAD: case TEE_ALG_DES3_CBC_NOPAD: - rc=handle->SE_process(handle, src_addr, src_size, dst_addr, dst_size); + rc = handle->SE_process(handle, src_addr, src_size, dst_addr, dst_size); break; case TEE_ALG_HMAC_MD5: @@ -533,7 +531,7 @@ static int sw_crypto_ioctl_update (crypto_internal_operation *operation, unsigne case TEE_ALG_AES_CMAC: case TEE_ALG_DES3_CBC_MAC_NOPAD: case TEE_ALG_DES3_CBC_MAC_PKCS5: - rc=handle->MAC_update(handle, src_addr, src_size); + rc = handle->MAC_update(handle, src_addr, src_size); break; case TEE_ALG_MD5: @@ -542,25 +540,28 @@ static int sw_crypto_ioctl_update (crypto_internal_operation *operation, unsigne case TEE_ALG_SHA256: case TEE_ALG_SHA384: case TEE_ALG_SHA512: - rc=handle->MD_update(handle, src_addr, src_size); + rc = handle->MD_update(handle, src_addr, src_size); break; default: LOGE(SSF_LIB, "Not Support Algorithm : %X", operation->info.algorithm); - rc=-1; + rc = -1; break; } - if(src_size && dst_size) {CRYPTO_INTERNAL_LOG("rc=%d src_size=%d dst_size=%d", rc, src_size, *dst_size);} - else {CRYPTO_INTERNAL_LOG("rc=%d", rc);} + if(src_size && dst_size) { + CRYPTO_INTERNAL_LOG("rc=%d src_size=%d dst_size=%d", rc, src_size, *dst_size); + } else { + CRYPTO_INTERNAL_LOG("rc=%d", rc); + } return rc; } -static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned char* src_addr, unsigned int src_size, unsigned char* dst_addr, unsigned int* dst_size) +static int sw_crypto_ioctl_final(crypto_internal_operation *operation, unsigned char* src_addr, unsigned int src_size, unsigned char* dst_addr, unsigned int* dst_size) { - int rc=-1; - int result=0; - CryptoCoreContainer *handle=(CryptoCoreContainer *)operation->crypto; + int rc = -1; + int result = 0; + CryptoCoreContainer *handle = (CryptoCoreContainer *)operation->crypto; switch(operation->info.algorithm) { @@ -577,7 +578,7 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned case TEE_ALG_AES_CBC_ISO9797_M2: case TEE_ALG_AES_CTR_NOPAD: case TEE_ALG_AES_CTR: - rc=handle->SE_final(handle, src_addr, src_size, dst_addr, dst_size); + rc = handle->SE_final(handle, src_addr, src_size, dst_addr, dst_size); break; case TEE_ALG_AES_CTS: @@ -588,7 +589,7 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned case TEE_ALG_DES3_ECB_NOPAD: case TEE_ALG_DES_CBC_NOPAD: case TEE_ALG_DES3_CBC_NOPAD: - rc=handle->SE_final(handle, src_addr, src_size, dst_addr, dst_size); + rc = handle->SE_final(handle, src_addr, src_size, dst_addr, dst_size); break; /* TEE_OPERATION_MAC */ @@ -605,10 +606,10 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned case TEE_ALG_AES_CMAC: case TEE_ALG_DES3_CBC_MAC_NOPAD: case TEE_ALG_DES3_CBC_MAC_PKCS5: - if(src_addr && src_size!=0) { + if(src_addr && src_size != 0) { handle->MAC_update(handle, src_addr, src_size); } - rc=handle->MAC_final(handle, dst_addr, dst_size); + rc = handle->MAC_final(handle, dst_addr, dst_size); break; /* TEE_OPERATION_AE */ @@ -623,10 +624,10 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned case TEE_ALG_SHA256: case TEE_ALG_SHA384: case TEE_ALG_SHA512: - if(src_addr && src_size!=0) { + if(src_addr && src_size != 0) { handle->MD_update(handle, src_addr, src_size); } - rc=handle->MD_final(handle, dst_addr); + rc = handle->MD_final(handle, dst_addr); *dst_size = operation->info.digestLength; break; @@ -639,10 +640,9 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512: if (operation->info.mode == TEE_MODE_ENCRYPT ) { - rc=handle->AE_encrypt(handle, src_addr, src_size, dst_addr, dst_size); - } - else{ - rc=handle->AE_decrypt(handle, src_addr, src_size, dst_addr, dst_size); + rc = handle->AE_encrypt(handle, src_addr, src_size, dst_addr, dst_size); + } else { + rc = handle->AE_decrypt(handle, src_addr, src_size, dst_addr, dst_size); } break; @@ -659,22 +659,21 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512: if (operation->info.mode == TEE_MODE_SIGN ) { - rc=handle->DS_sign(handle, src_addr, src_size, dst_addr, dst_size); - } - else { - rc=handle->DS_verify(handle, src_addr, src_size, dst_addr, *dst_size, &result); + rc = handle->DS_sign(handle, src_addr, src_size, dst_addr, dst_size); + } else { + rc = handle->DS_verify(handle, src_addr, src_size, dst_addr, *dst_size, &result); if(result != rc) { - rc=result; + rc = result; } } break; case TEE_ALG_GENERATE_SECRET_KEY: - rc=0; + rc = 0; break; case TEE_ALG_GENERATE_RSA_KEY: - rc=0; + rc = 0; break; default: @@ -682,8 +681,11 @@ static int sw_crypto_ioctl_final (crypto_internal_operation *operation, unsigned break; } - if(src_size && dst_size) {CRYPTO_INTERNAL_LOG("rc=%d src_size=%d dst_size=%d", rc, src_size, *dst_size);} - else {CRYPTO_INTERNAL_LOG("rc=%d", rc);} + if(src_size && dst_size) { + CRYPTO_INTERNAL_LOG("rc=%d src_size=%d dst_size=%d", rc, src_size, *dst_size); + } else { + CRYPTO_INTERNAL_LOG("rc=%d", rc); + } return rc; } @@ -706,16 +708,13 @@ static int sw_crypto_open(crypto_internal_operation *operation) case TEE_ALG_AES_CBC_PKCS7: case TEE_ALG_AES_CBC_ISO9797_M1: case TEE_ALG_AES_CBC_ISO9797_M2: - if (operation->info.keySize== 128) { - alg=ID_AES128; - } - else if (operation->info.keySize== 192) { - alg=ID_AES192; - } - else if (operation->info.keySize== 256) { - alg=ID_AES256; - } - else { + if (operation->info.keySize == 128) { + alg = ID_AES128; + } else if (operation->info.keySize == 192) { + alg = ID_AES192; + } else if (operation->info.keySize == 256) { + alg = ID_AES256; + } else { goto error; } break; @@ -725,11 +724,11 @@ static int sw_crypto_open(crypto_internal_operation *operation) break; case TEE_ALG_DES_ECB_NOPAD: case TEE_ALG_DES_CBC_NOPAD: - alg=ID_DES; + alg = ID_DES; break; case TEE_ALG_DES3_ECB_NOPAD: case TEE_ALG_DES3_CBC_NOPAD: - alg=ID_TDES; + alg = ID_TDES; break; /* TEE_OPERATION_MAC */ @@ -795,22 +794,17 @@ static int sw_crypto_open(crypto_internal_operation *operation) case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA256: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA384: case TEE_ALG_RSAES_PKCS1_OAEP_MGF1_SHA512: - if (operation->info.keySize== 512) { - alg=ID_RSA512; - } - else if (operation->info.keySize== 1024) { - alg=ID_RSA1024; - } - else if (operation->info.keySize== 2048) { - alg=ID_RSA2048; - } - else if (operation->info.keySize== 3072) { - alg=ID_RSA3072; - } - else if (operation->info.keySize== 4096) { - alg=ID_RSA4096; - } - else { + if (operation->info.keySize == 512) { + alg = ID_RSA512; + } else if (operation->info.keySize == 1024) { + alg = ID_RSA1024; + } else if (operation->info.keySize == 2048) { + alg = ID_RSA2048; + } else if (operation->info.keySize == 3072) { + alg = ID_RSA3072; + } else if (operation->info.keySize == 4096) { + alg = ID_RSA4096; + } else { goto error; } break; @@ -827,22 +821,17 @@ static int sw_crypto_open(crypto_internal_operation *operation) case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA256: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA384: case TEE_ALG_RSASSA_PKCS1_PSS_MGF1_SHA512: - if (operation->info.keySize== 512) { - alg=ID_RSA512; - } - else if (operation->info.keySize== 1024) { - alg=ID_RSA1024; - } - else if (operation->info.keySize== 2048) { - alg=ID_RSA2048; - } - else if (operation->info.keySize== 3072) { - alg=ID_RSA3072; - } - else if (operation->info.keySize== 4096) { - alg=ID_RSA4096; - } - else { + if (operation->info.keySize == 512) { + alg = ID_RSA512; + } else if (operation->info.keySize == 1024) { + alg = ID_RSA1024; + } else if (operation->info.keySize == 2048) { + alg = ID_RSA2048; + } else if (operation->info.keySize == 3072) { + alg = ID_RSA3072; + } else if (operation->info.keySize == 4096) { + alg = ID_RSA4096; + } else { goto error; } break; @@ -874,26 +863,21 @@ static int sw_crypto_open(crypto_internal_operation *operation) break; case TEE_ALG_GENERATE_SECRET_KEY: - alg=ID_X931; + alg = ID_X931; break; case TEE_ALG_GENERATE_RSA_KEY: - if (operation->info.keySize== 512) { - alg=ID_RSA512; - } - else if (operation->info.keySize== 1024) { - alg=ID_RSA1024; - } - else if (operation->info.keySize== 2048) { - alg=ID_RSA2048; - } - else if (operation->info.keySize== 3072) { - alg=ID_RSA3072; - } - else if (operation->info.keySize== 4096) { - alg=ID_RSA4096; - } - else { + if (operation->info.keySize == 512) { + alg = ID_RSA512; + } else if (operation->info.keySize == 1024) { + alg = ID_RSA1024; + } else if (operation->info.keySize == 2048) { + alg = ID_RSA2048; + } else if (operation->info.keySize == 3072) { + alg = ID_RSA3072; + } else if (operation->info.keySize == 4096) { + alg = ID_RSA4096; + } else { goto error; } break; @@ -951,28 +935,28 @@ int crypto_internal_init(crypto_internal_operation *operation, crypto_internal_k int crypto_internal_update(crypto_internal_operation *operation, unsigned char *src_data, size_t src_len, unsigned char *dst_data, size_t *dst_len) { - unsigned char* in_data=NULL; - unsigned char* out_data=NULL; - unsigned int in_size=0; - unsigned int out_size=0; - unsigned int num=0; - unsigned int processing_len=0; - unsigned int total_processing_len=0; + unsigned char* in_data = NULL; + unsigned char* out_data = NULL; + unsigned int in_size = 0; + unsigned int out_size = 0; + unsigned int num = 0; + unsigned int processing_len = 0; + unsigned int total_processing_len = 0; int (*crypto_update_engine)(crypto_internal_operation *, unsigned char *, unsigned int, unsigned char *, unsigned int*); - crypto_update_engine=sw_crypto_ioctl_update; + crypto_update_engine = sw_crypto_ioctl_update; if(src_data) { - in_data=(unsigned char*)src_data; + in_data = (unsigned char*)src_data; } if(dst_data) { - out_data=(unsigned char*)dst_data; + out_data = (unsigned char*)dst_data; } if(src_len) { - in_size=(unsigned int)src_len; + in_size = (unsigned int)src_len; } if(dst_len) { - out_size=(unsigned int)*dst_len; + out_size = (unsigned int)*dst_len; } CRYPTO_INTERNAL_LOG("--------------------------------------------------------------"); @@ -984,8 +968,7 @@ int crypto_internal_update(crypto_internal_operation *operation, unsigned char * { if (in_size < (size_t)(operation->block_len - operation->data_len)) { num = in_size; - } - else { + } else { num = (size_t)(operation->block_len - operation->data_len); } @@ -1035,15 +1018,12 @@ int crypto_internal_update(crypto_internal_operation *operation, unsigned char * operation->data_len = remaining_number_of_bytes; } } - } - else if(operation->info.operationClass == TEE_OPERATION_MAC || operation->info.operationClass == TEE_OPERATION_DIGEST) - { + } else if (operation->info.operationClass == TEE_OPERATION_MAC || operation->info.operationClass == TEE_OPERATION_DIGEST) { if (operation->data_len != 0) { if (in_size < (size_t)(operation->block_len - operation->data_len)) { num = in_size; - } - else { + } else { num = (size_t)(operation->block_len - operation->data_len); } @@ -1092,9 +1072,7 @@ int crypto_internal_update(crypto_internal_operation *operation, unsigned char * in_size -= remaining_number_of_bytes; } } - } - else - { + } else { if(crypto_update_engine(operation, in_data, in_size, out_data, &out_size)) { goto error; } @@ -1112,30 +1090,30 @@ error: int crypto_internal_final(crypto_internal_operation *operation, unsigned char *src_data, size_t src_len, unsigned char *dst_data, size_t *dst_len) { - unsigned char* in_data=NULL; - unsigned char* out_data=NULL; - unsigned int in_size=0; - unsigned int out_size=0; - unsigned int num=0; - unsigned int processing_len=0; - unsigned int total_processing_len=0; + unsigned char* in_data = NULL; + unsigned char* out_data = NULL; + unsigned int in_size = 0; + unsigned int out_size = 0; + unsigned int num = 0; + unsigned int processing_len = 0; + unsigned int total_processing_len = 0; int (*crypto_update_engine)(crypto_internal_operation *, unsigned char *, unsigned int, unsigned char *, unsigned int*); int (*crypto_final_engine)(crypto_internal_operation *, unsigned char *, unsigned int, unsigned char *, unsigned int*); - crypto_update_engine=sw_crypto_ioctl_update; - crypto_final_engine=sw_crypto_ioctl_final; + crypto_update_engine = sw_crypto_ioctl_update; + crypto_final_engine = sw_crypto_ioctl_final; if(src_data) { - in_data=(unsigned char*)src_data; + in_data = (unsigned char*)src_data; } if(dst_data) { - out_data=(unsigned char*)dst_data; + out_data = (unsigned char*)dst_data; } if(src_len) { - in_size=(unsigned int)src_len; + in_size = (unsigned int)src_len; } if(dst_len) { - out_size=(unsigned int)*dst_len; + out_size = (unsigned int)*dst_len; } CRYPTO_INTERNAL_LOG("--------------------------------------------------------------"); @@ -1147,8 +1125,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s { if (in_size < (size_t)(operation->block_len - operation->data_len)) { num = in_size; - } - else { + } else { num = (size_t)(operation->block_len - operation->data_len); } @@ -1200,15 +1177,15 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s out_data = (unsigned char*)((unsigned long) out_data + processing_len); } - if(operation->info.mode==TEE_MODE_ENCRYPT) + if (operation->info.mode == TEE_MODE_ENCRYPT) { unsigned int pad_byte; size_t should_be_processed_of_pad_bytes = 0; /* NOPAD */ - if (operation->info.algorithm==TEE_ALG_AES_ECB_NOPAD ||operation->info.algorithm==TEE_ALG_AES_CBC_NOPAD|| - operation->info.algorithm==TEE_ALG_DES_ECB_NOPAD ||operation->info.algorithm==TEE_ALG_DES_CBC_NOPAD|| - operation->info.algorithm==TEE_ALG_DES3_ECB_NOPAD || operation->info.algorithm==TEE_ALG_DES3_CBC_NOPAD) + if (operation->info.algorithm == TEE_ALG_AES_ECB_NOPAD || operation->info.algorithm == TEE_ALG_AES_CBC_NOPAD || + operation->info.algorithm == TEE_ALG_DES_ECB_NOPAD || operation->info.algorithm == TEE_ALG_DES_CBC_NOPAD || + operation->info.algorithm == TEE_ALG_DES3_ECB_NOPAD || operation->info.algorithm == TEE_ALG_DES3_CBC_NOPAD) { CRYPTO_INTERNAL_LOG("ENC NOPAD : Ignore remaining_number_of_bytes=%zd !!", remaining_number_of_bytes); goto exit; @@ -1223,32 +1200,24 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s pad_byte = operation->block_len - remaining_number_of_bytes; - if (operation->info.algorithm==TEE_ALG_AES_ECB_PKCS5 ||operation->info.algorithm==TEE_ALG_AES_ECB_PKCS7 || - operation->info.algorithm==TEE_ALG_AES_CBC_PKCS5 ||operation->info.algorithm==TEE_ALG_AES_CBC_PKCS7) - { + if (operation->info.algorithm == TEE_ALG_AES_ECB_PKCS5 || operation->info.algorithm == TEE_ALG_AES_ECB_PKCS7 || + operation->info.algorithm == TEE_ALG_AES_CBC_PKCS5 || operation->info.algorithm == TEE_ALG_AES_CBC_PKCS7) { should_be_processed_of_pad_bytes = operation->block_len; memset(operation->data + operation->data_len, pad_byte, pad_byte); CRYPTO_INTERNAL_LOG("ENC PKCS : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[0], operation->data[1], operation->data[2], operation->data[3], operation->data[4], operation->data[5], operation->data[6], operation->data[7]); CRYPTO_INTERNAL_LOG("ENC PKCS : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[8], operation->data[9], operation->data[10], operation->data[11], operation->data[12], operation->data[13], operation->data[14], operation->data[15]); - } - else if(operation->info.algorithm==TEE_ALG_AES_ECB_ISO9797_M1 ||operation->info.algorithm==TEE_ALG_AES_CBC_ISO9797_M1) - { - if(pad_byte != 0 && (operation->block_len != pad_byte)) - { + } else if (operation->info.algorithm == TEE_ALG_AES_ECB_ISO9797_M1 || operation->info.algorithm == TEE_ALG_AES_CBC_ISO9797_M1) { + if (pad_byte != 0 && (operation->block_len != pad_byte)) { should_be_processed_of_pad_bytes = operation->block_len; memset(operation->data + operation->data_len, 0x00, pad_byte); CRYPTO_INTERNAL_LOG("ENC ZERO : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[0], operation->data[1], operation->data[2], operation->data[3], operation->data[4], operation->data[5], operation->data[6], operation->data[7]); CRYPTO_INTERNAL_LOG("ENC ZERO : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[8], operation->data[9], operation->data[10], operation->data[11], operation->data[12], operation->data[13], operation->data[14], operation->data[15]); - } - else - { + } else { should_be_processed_of_pad_bytes = 0; } - } - else if (operation->info.algorithm==TEE_ALG_AES_ECB_ISO9797_M2 || operation->info.algorithm==TEE_ALG_AES_CBC_ISO9797_M2) - { + } else if (operation->info.algorithm == TEE_ALG_AES_ECB_ISO9797_M2 || operation->info.algorithm == TEE_ALG_AES_CBC_ISO9797_M2) { should_be_processed_of_pad_bytes = operation->block_len; memset(operation->data + operation->data_len, 0x00, pad_byte); @@ -1258,9 +1227,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s operation->data[operation->data_len] = 0x80; CRYPTO_INTERNAL_LOG("ENC ISO9797 : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[0], operation->data[1], operation->data[2], operation->data[3], operation->data[4], operation->data[5], operation->data[6], operation->data[7]); CRYPTO_INTERNAL_LOG("ENC ISO9797 : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[8], operation->data[9], operation->data[10], operation->data[11], operation->data[12], operation->data[13], operation->data[14], operation->data[15]); - } - else if(operation->info.algorithm==TEE_ALG_AES_CTR || operation->info.algorithm==TEE_ALG_AES_CTR_NOPAD) - { + } else if (operation->info.algorithm == TEE_ALG_AES_CTR || operation->info.algorithm == TEE_ALG_AES_CTR_NOPAD) { should_be_processed_of_pad_bytes = remaining_number_of_bytes; } @@ -1269,23 +1236,18 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s } total_processing_len += processing_len; - } - else if(operation->info.mode==TEE_MODE_DECRYPT) { + } else if (operation->info.mode == TEE_MODE_DECRYPT) { unsigned char * pad = out_data; - unsigned int npad=0; + unsigned int npad = 0; - if (operation->info.algorithm==TEE_ALG_AES_ECB_NOPAD || operation->info.algorithm==TEE_ALG_AES_CBC_NOPAD|| - operation->info.algorithm==TEE_ALG_DES_ECB_NOPAD || operation->info.algorithm==TEE_ALG_DES_CBC_NOPAD|| - operation->info.algorithm==TEE_ALG_DES3_ECB_NOPAD || operation->info.algorithm==TEE_ALG_DES3_CBC_NOPAD) - { + if (operation->info.algorithm == TEE_ALG_AES_ECB_NOPAD || operation->info.algorithm == TEE_ALG_AES_CBC_NOPAD || + operation->info.algorithm == TEE_ALG_DES_ECB_NOPAD || operation->info.algorithm == TEE_ALG_DES_CBC_NOPAD || + operation->info.algorithm == TEE_ALG_DES3_ECB_NOPAD || operation->info.algorithm == TEE_ALG_DES3_CBC_NOPAD) { CRYPTO_INTERNAL_LOG("DEC NOPAD : Ignore remaining_number_of_bytes=%zd !!", remaining_number_of_bytes); goto exit; - } /* PAD */ - else if ( - operation->info.algorithm==TEE_ALG_AES_ECB_PKCS5 ||operation->info.algorithm==TEE_ALG_AES_ECB_PKCS7 || - operation->info.algorithm==TEE_ALG_AES_CBC_PKCS5 ||operation->info.algorithm==TEE_ALG_AES_CBC_PKCS7) - { + } else if (operation->info.algorithm == TEE_ALG_AES_ECB_PKCS5 || operation->info.algorithm == TEE_ALG_AES_ECB_PKCS7 || + operation->info.algorithm == TEE_ALG_AES_CBC_PKCS5 || operation->info.algorithm == TEE_ALG_AES_CBC_PKCS7) { memcpy(operation->data, pad-operation->block_len, operation->block_len); CRYPTO_INTERNAL_LOG("DEC PKCS : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[0], operation->data[1], operation->data[2], operation->data[3], operation->data[4], operation->data[5], operation->data[6], operation->data[7]); CRYPTO_INTERNAL_LOG("DEC PKCS : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[8], operation->data[9], operation->data[10], operation->data[11], operation->data[12], operation->data[13], operation->data[14], operation->data[15]); @@ -1293,8 +1255,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s pad--; //last byte npad = *pad; - if (npad <= operation->block_len) // can't be more than block length - { + if (npad <= operation->block_len) { // can't be more than block length unsigned int i; int ok = 1; for(i = 0; i < npad; i++, pad--) { @@ -1308,14 +1269,10 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s total_processing_len -= npad; // padding OK. Othewise padding will not be removed } } - } - else if(operation->info.algorithm==TEE_ALG_AES_ECB_ISO9797_M1 ||operation->info.algorithm==TEE_ALG_AES_CBC_ISO9797_M1) - { + } else if (operation->info.algorithm == TEE_ALG_AES_ECB_ISO9797_M1 ||operation->info.algorithm == TEE_ALG_AES_CBC_ISO9797_M1) { CRYPTO_INTERNAL_LOG("DEC ISO9797 M1 : Ignore remaining_number_of_bytes=%zd !!", remaining_number_of_bytes); goto exit; - } - else if (operation->info.algorithm==TEE_ALG_AES_ECB_ISO9797_M2 || operation->info.algorithm==TEE_ALG_AES_CBC_ISO9797_M2) - { + } else if (operation->info.algorithm == TEE_ALG_AES_ECB_ISO9797_M2 || operation->info.algorithm == TEE_ALG_AES_CBC_ISO9797_M2) { memcpy(operation->data, pad-operation->block_len, operation->block_len); CRYPTO_INTERNAL_LOG("DEC ISO9797 M2 : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[0], operation->data[1], operation->data[2], operation->data[3], operation->data[4], operation->data[5], operation->data[6], operation->data[7]); CRYPTO_INTERNAL_LOG("DEC ISO9797 M2 : op->data=%2X%2X%2X%2X%2X%2X%2X%2X", operation->data[8], operation->data[9], operation->data[10], operation->data[11], operation->data[12], operation->data[13], operation->data[14], operation->data[15]); @@ -1323,20 +1280,17 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s pad--; //last byte npad = 0; - if (*pad==0x00) // remove 0s - for(; npad < operation->block_len-1 && *pad==0x00; npad++,pad--); + if (*pad == 0x00) // remove 0s + for (; npad < operation->block_len-1 && *pad == 0x00; npad++, pad--); - if (*pad==0x80) { // correct M2 padding + if (*pad == 0x80) { // correct M2 padding npad++; // remove 1st PAD byte 0x80 - } - else { // M2 padding error + } else { // M2 padding error npad = 0; // don't remove any padding } total_processing_len -= npad; - } - else if(operation->info.algorithm==TEE_ALG_AES_CTR || operation->info.algorithm==TEE_ALG_AES_CTR_NOPAD) - { + } else if (operation->info.algorithm == TEE_ALG_AES_CTR || operation->info.algorithm == TEE_ALG_AES_CTR_NOPAD) { memcpy(operation->data, in_data, remaining_number_of_bytes); operation->data_len += remaining_number_of_bytes; @@ -1345,26 +1299,20 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s } total_processing_len += remaining_number_of_bytes; } - } - else - { + } else { goto error; } } - } - else if(operation->info.operationClass == TEE_OPERATION_MAC || operation->info.operationClass == TEE_OPERATION_DIGEST) - { - if (operation->data_len != 0) - { + } else if (operation->info.operationClass == TEE_OPERATION_MAC || operation->info.operationClass == TEE_OPERATION_DIGEST) { + if (operation->data_len != 0) { if (in_size < (size_t)(operation->block_len - operation->data_len)) { num = in_size; - } - else { + } else { num = (size_t)(operation->block_len - operation->data_len); } CRYPTO_INTERNAL_LOG("num=%d in_size=%d processed=%d", num, in_size, total_processing_len); - if(num != 0) { + if (num != 0) { memcpy(operation->data + operation->data_len, in_data, num); operation->data_len += num; @@ -1372,8 +1320,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s in_data = (unsigned char*)((unsigned long)in_data + num); /* accumulated data is full */ - if (operation->data_len == operation->block_len) - { + if (operation->data_len == operation->block_len) { if (crypto_update_engine(operation, operation->data, operation->data_len, NULL, NULL)) { goto error; } @@ -1389,17 +1336,14 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s CRYPTO_INTERNAL_LOG("num=%d in_size=%d op->data_len=%d", num, in_size, operation->data_len); } - if (in_size != 0) - { - if(crypto_final_engine(operation, in_data, in_size, out_data, &out_size)) { + if (in_size != 0) { + if (crypto_final_engine(operation, in_data, in_size, out_data, &out_size)) { goto error; } total_processing_len += in_size; } - } - else - { - if(crypto_final_engine(operation, in_data, in_size, out_data, &out_size)) { + } else { + if (crypto_final_engine(operation, in_data, in_size, out_data, &out_size)) { goto error; } total_processing_len += in_size; @@ -1407,22 +1351,17 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s exit: CRYPTO_INTERNAL_LOG("in_size=%d out_size=%d processed=%d", in_size, out_size, total_processing_len); CRYPTO_INTERNAL_LOG("--------------------------------------------------------------"); - if(operation->info.operationClass == TEE_OPERATION_CIPHER && dst_len) { + if (operation->info.operationClass == TEE_OPERATION_CIPHER && dst_len) { *dst_len = total_processing_len; - } - else if(operation->info.operationClass == TEE_OPERATION_MAC && dst_len) { + } else if (operation->info.operationClass == TEE_OPERATION_MAC && dst_len) { *dst_len = out_size; - } - else if(operation->info.operationClass == TEE_OPERATION_AE && dst_len) { + } else if (operation->info.operationClass == TEE_OPERATION_AE && dst_len) { *dst_len = total_processing_len; - } - else if(operation->info.operationClass == TEE_OPERATION_DIGEST && dst_len) { + } else if (operation->info.operationClass == TEE_OPERATION_DIGEST && dst_len) { *dst_len = out_size; - } - else if(operation->info.operationClass == TEE_OPERATION_ASYMMETRIC_CIPHER && dst_len) { + } else if (operation->info.operationClass == TEE_OPERATION_ASYMMETRIC_CIPHER && dst_len) { *dst_len = out_size; - } - else if(operation->info.operationClass == TEE_OPERATION_ASYMMETRIC_SIGNATURE && dst_len) { + } else if (operation->info.operationClass == TEE_OPERATION_ASYMMETRIC_SIGNATURE && dst_len) { *dst_len = out_size; } return 0; @@ -1439,7 +1378,7 @@ TEE_Result TEE_AllocateOperation(TEE_OperationHandle *operation, uint32_t algori { PERMISSION_CHECK(PERM_CRYPTO); crypto_internal_operation * op; - TEE_Result rc=TEE_SUCCESS; + TEE_Result rc = TEE_SUCCESS; uint32_t alg_class = 0; uint32_t key_object_type = 0; uint32_t digest_len = 0; @@ -1834,8 +1773,7 @@ TEE_Result TEE_AllocateOperation(TEE_OperationHandle *operation, uint32_t algori { if (mode == TEE_MODE_ENCRYPT) { op->info.requiredKeyUsage |= TEE_USAGE_VERIFY; - } - else if (mode == TEE_MODE_DECRYPT) { + } else if (mode == TEE_MODE_DECRYPT) { op->info.requiredKeyUsage |= TEE_USAGE_SIGN; } } @@ -1845,7 +1783,7 @@ TEE_Result TEE_AllocateOperation(TEE_OperationHandle *operation, uint32_t algori } /* get handle */ - if (crypto_internal_open(op)!=0) { + if (crypto_internal_open(op) != 0) { rc = TEE_ERROR_NOT_SUPPORTED; goto error; } @@ -1917,7 +1855,7 @@ void TEE_FreeOperation(TEE_OperationHandle operation) return; } -void TEE_GetOperationInfo( TEE_OperationHandle operation, TEE_OperationInfo* operationInfo) +void TEE_GetOperationInfo(TEE_OperationHandle operation, TEE_OperationInfo* operationInfo) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); @@ -1933,7 +1871,7 @@ void TEE_GetOperationInfo( TEE_OperationHandle operation, TEE_OperationInfo* ope operationInfo->requiredKeyUsage = op->info.requiredKeyUsage; } -void TEE_ResetOperation( TEE_OperationHandle operation) +void TEE_ResetOperation(TEE_OperationHandle operation) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); @@ -1942,7 +1880,7 @@ void TEE_ResetOperation( TEE_OperationHandle operation) return; } -TEE_Result TEE_SetOperationKey( TEE_OperationHandle operation, TEE_ObjectHandle key) +TEE_Result TEE_SetOperationKey(TEE_OperationHandle operation, TEE_ObjectHandle key) { PERMISSION_CHECK(PERM_CRYPTO); @@ -1951,7 +1889,6 @@ TEE_Result TEE_SetOperationKey( TEE_OperationHandle operation, TEE_ObjectHandle { LOGE(SSF_LIB, "op->info.operationClass == TEE_OPERATION_DIGEST\n"); return TEE_ERROR_BAD_PARAMETERS; - }; if (key == TEE_HANDLE_NULL) @@ -1965,7 +1902,6 @@ TEE_Result TEE_SetOperationKey( TEE_OperationHandle operation, TEE_ObjectHandle { LOGE(SSF_LIB, "(key->tr.info.objectUsage | ~(op->info.requiredKeyUsage)) != 0xffffffff\n"); return TEE_ERROR_BAD_PARAMETERS; - }; TEE_CopyObjectAttributes(op->key1, key); @@ -1974,7 +1910,7 @@ TEE_Result TEE_SetOperationKey( TEE_OperationHandle operation, TEE_ObjectHandle return TEE_SUCCESS; } -TEE_Result TEE_SetOperationKey2( TEE_OperationHandle operation, TEE_ObjectHandle key1, TEE_ObjectHandle key2) +TEE_Result TEE_SetOperationKey2(TEE_OperationHandle operation, TEE_ObjectHandle key1, TEE_ObjectHandle key2) { PERMISSION_CHECK(PERM_CRYPTO); @@ -2016,7 +1952,7 @@ TEE_Result TEE_SetOperationKey2( TEE_OperationHandle operation, TEE_ObjectHandle } -void TEE_CopyOperation( TEE_OperationHandle dstOperation, TEE_OperationHandle srcOperation) +void TEE_CopyOperation(TEE_OperationHandle dstOperation, TEE_OperationHandle srcOperation) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); @@ -2049,8 +1985,7 @@ void TEE_CopyOperation( TEE_OperationHandle dstOperation, TEE_OperationHandle sr if (crypto_internal_open(dstOp) != 0) { CRYPTO_PANIC; } - } - else { + } else { dstOp->crypto = NULL; } return; @@ -2072,7 +2007,7 @@ void TEE_DigestInit(TEE_OperationHandle operation) return; } -void TEE_DigestUpdate( TEE_OperationHandle operation, const void* chunk, size_t chunkSize) +void TEE_DigestUpdate(TEE_OperationHandle operation, const void* chunk, size_t chunkSize) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2092,7 +2027,7 @@ void TEE_DigestUpdate( TEE_OperationHandle operation, const void* chunk, size_t return; } -TEE_Result TEE_DigestDoFinal( TEE_OperationHandle operation, const void* chunk, size_t chunkLen, void* hash, size_t *hashLen) +TEE_Result TEE_DigestDoFinal(TEE_OperationHandle operation, const void* chunk, size_t chunkLen, void* hash, size_t *hashLen) { PERMISSION_CHECK(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2113,7 +2048,7 @@ TEE_Result TEE_DigestDoFinal( TEE_OperationHandle operation, const void* chunk, } // Symmetric Cipher Functions -void TEE_CipherInit( TEE_OperationHandle operation, const void* IV, size_t IVLen) +void TEE_CipherInit(TEE_OperationHandle operation, const void* IV, size_t IVLen) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2144,7 +2079,7 @@ void TEE_CipherInit( TEE_OperationHandle operation, const void* IV, size_t IVLen return; } -TEE_Result TEE_CipherUpdate( TEE_OperationHandle operation, const void* srcData, size_t srcLen, void* destData, size_t *destLen) +TEE_Result TEE_CipherUpdate(TEE_OperationHandle operation, const void* srcData, size_t srcLen, void* destData, size_t *destLen) { PERMISSION_CHECK(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2164,7 +2099,7 @@ TEE_Result TEE_CipherUpdate( TEE_OperationHandle operation, const void* srcData, return TEE_SUCCESS; } -TEE_Result TEE_CipherDoFinal( TEE_OperationHandle operation, const void* srcData, size_t srcLen, void* destData, size_t *destLen) +TEE_Result TEE_CipherDoFinal(TEE_OperationHandle operation, const void* srcData, size_t srcLen, void* destData, size_t *destLen) { PERMISSION_CHECK(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2185,7 +2120,7 @@ TEE_Result TEE_CipherDoFinal( TEE_OperationHandle operation, const void* srcData } // MAC Functions -void TEE_MACInit( TEE_OperationHandle operation, const void* IV, size_t IVLen) +void TEE_MACInit(TEE_OperationHandle operation, const void* IV, size_t IVLen) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2216,7 +2151,7 @@ void TEE_MACInit( TEE_OperationHandle operation, const void* IV, size_t IVLen) return; } -void TEE_MACUpdate( TEE_OperationHandle operation, const void* chunk, size_t chunkSize) +void TEE_MACUpdate(TEE_OperationHandle operation, const void* chunk, size_t chunkSize) { PERMISSION_CHECK_RETURN_VOID(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2236,7 +2171,7 @@ void TEE_MACUpdate( TEE_OperationHandle operation, const void* chunk, size_t chu return; } -TEE_Result TEE_MACComputeFinal( TEE_OperationHandle operation, const void* message, size_t messageLen, void* mac, size_t *macLen) +TEE_Result TEE_MACComputeFinal(TEE_OperationHandle operation, const void* message, size_t messageLen, void* mac, size_t *macLen) { PERMISSION_CHECK(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2256,7 +2191,7 @@ TEE_Result TEE_MACComputeFinal( TEE_OperationHandle operation, const void* messa return TEE_SUCCESS; } -TEE_Result TEE_MACCompareFinal( TEE_OperationHandle operation, void* message, size_t messageLen, void* mac, size_t *macLen) +TEE_Result TEE_MACCompareFinal(TEE_OperationHandle operation, void* message, size_t messageLen, void* mac, size_t *macLen) { PERMISSION_CHECK(PERM_CRYPTO); crypto_internal_operation * op = (crypto_internal_operation*) operation; @@ -2476,7 +2411,7 @@ TEE_Result TEE_AEDecryptFinal(TEE_OperationHandle operation, void* srcData, size return ret; } -TEE_Result TEE_AsymmetricEncrypt( TEE_OperationHandle operation,const TEE_Attribute* params, uint32_t paramCount, const void* srcData, size_t srcLen, void* destData, size_t *destLen) +TEE_Result TEE_AsymmetricEncrypt(TEE_OperationHandle operation, const TEE_Attribute* params, uint32_t paramCount, const void* srcData, size_t srcLen, void* destData, size_t *destLen) { PERMISSION_CHECK(PERM_CRYPTO); (void)params; @@ -2521,7 +2456,7 @@ TEE_Result TEE_AsymmetricEncrypt( TEE_OperationHandle operation,const TEE_Attrib return TEE_SUCCESS; } -TEE_Result TEE_AsymmetricDecrypt( TEE_OperationHandle operation, const TEE_Attribute* params, uint32_t paramCount, const void* srcData, size_t srcLen, void* destData, size_t *destLen) +TEE_Result TEE_AsymmetricDecrypt(TEE_OperationHandle operation, const TEE_Attribute* params, uint32_t paramCount, const void* srcData, size_t srcLen, void* destData, size_t *destLen) { PERMISSION_CHECK(PERM_CRYPTO); @@ -2753,7 +2688,7 @@ void TEE_GenerateRandom(void* randomBuffer, size_t randomBufferLen) key.secret.buffer = random; key.secret.size = random_len*8; - if (crypto_internal_open(&op)!=0) { + if (crypto_internal_open(&op) != 0) { CRYPTO_PANIC; } if (crypto_internal_init(&op, &key, NULL, 0)) { diff --git a/ssflib/src/ssf_lib.cpp b/ssflib/src/ssf_lib.cpp index b9d2905..d9b17f7 100644 --- a/ssflib/src/ssf_lib.cpp +++ b/ssflib/src/ssf_lib.cpp @@ -47,7 +47,6 @@ extern "C"{ * Initializes SSF for use by TA */ __attribute__((constructor)) void initializeSSF() { - socketSimulatorDaemonFD = connecttoServer(); assert(socketSimulatorDaemonFD != -1); LOGD(SIM_DAEMON, "Done");} diff --git a/ssflib/src/ssf_storage.cpp b/ssflib/src/ssf_storage.cpp index cfe01da..1b71c8e 100644 --- a/ssflib/src/ssf_storage.cpp +++ b/ssflib/src/ssf_storage.cpp @@ -33,8 +33,8 @@ /*----------------------------------------------------------------------------- * MACROS *-----------------------------------------------------------------------------*/ -#define __FREE(buf) if(buf) {OsaFree(buf); buf = NULL;} -#define FREE_PO(po) if(po) {clean_po_file(po);OsaFree(po); po = NULL;} +#define __FREE(buf) if (buf) {OsaFree(buf); buf = NULL;} +#define FREE_PO(po) if (po) {clean_po_file(po);OsaFree(po); po = NULL;} #define PO_INTERNAL_MODULE_NAME "po_file" #define PO_STAT_INTERNAL_MODULE_NAME "po_stat" @@ -407,7 +407,7 @@ TEE_Result create_po(persistent_object* po, TransientObject* attr, return TEE_ERROR_GENERIC; } // update po share info - if (0 != update_share_info(&po->share_info, po->attr.info.handleFlags,0, 1, po)) { + if (0 != update_share_info(&po->share_info, po->attr.info.handleFlags, 0, 1, po)) { return TEE_ERROR_GENERIC; } // add to po list @@ -1178,7 +1178,7 @@ void convert_TA_UUID(char* uuid, TEE_UUID TA_UUID) { tmp += 5; uint32_t i = 0; for (; i < 2; ++i) { - snprintf(tmp, 3,"%02x", TA_UUID.clockSeqAndNode[i]); + snprintf(tmp, 3, "%02x", TA_UUID.clockSeqAndNode[i]); tmp += 2; } tmp[0] = '-'; diff --git a/ssflib/src/ssf_taentrypoint.cpp b/ssflib/src/ssf_taentrypoint.cpp index cfb3396..5b66369 100644 --- a/ssflib/src/ssf_taentrypoint.cpp +++ b/ssflib/src/ssf_taentrypoint.cpp @@ -48,11 +48,11 @@ extern TEE_UUID ssf_sharedthisTAUUID; } else if (type == TEEC_NONE) { \ } else { \ int getOffset = 0; \ - if(params[i].memref.memid == 0) { \ + if (params[i].memref.memid == 0) { \ params[i].memref.memid = getSharedMemoryShmID(params[i].memref.buffer); \ } else { \ char* getAdd = getSharedMemoryAddress(params[i].memref.memid); \ - if(getAdd != 0) \ + if (getAdd != 0) \ getOffset = (char*)params[i].memref.buffer - getAdd; \ } \ data.operation.params[i].mem.offset = getOffset; \ @@ -132,7 +132,6 @@ TEE_Result TEE_OpenTASession(const TEE_UUID* destination, } void TEE_CloseTASession(TEE_TASessionHandle session) { - IntTACloseSessionData data; data.session = *(uint32_t*)session; pthread_mutex_lock(&socketLock); -- 2.7.4 From 1b8ee5fbf7a554a6ca5b18fc758f4e19799e9b93 Mon Sep 17 00:00:00 2001 From: Piotr Sawicki Date: Mon, 23 Oct 2017 09:04:14 +0200 Subject: [PATCH 11/16] Make changing of shm file mode thread safe Change-Id: Id7b07a203878fdf16414c3b3fae281918671d345 --- TEECLib/src/teec_api.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/TEECLib/src/teec_api.c b/TEECLib/src/teec_api.c index a84aac7..0860520 100644 --- a/TEECLib/src/teec_api.c +++ b/TEECLib/src/teec_api.c @@ -41,6 +41,7 @@ #define SHM_MAX_ID INT32_MAX #define SHM_NAME_TEMPLATE "/teec_shm%d" +#define SHM_FILE_MODE 0660 /*----------------------------------------------------------------------------- * Globals *-----------------------------------------------------------------------------*/ @@ -98,23 +99,27 @@ static int32_t allocateSharedMemory(TEEC_SharedMemory *shm) { int fd_shm = -1; int res; - mode_t origMask = umask(0); - do { res = snprintf(shm_name, sizeof(shm_name), SHM_NAME_TEMPLATE, memKey); if (res == sizeof(shm_name)) { - umask(origMask); LOGE(TEEC_LIB, "the shm object name is too long"); return TEEC_ERROR_GENERIC; } - fd_shm = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, 0660); + fd_shm = shm_open(shm_name, O_RDWR | O_CREAT | O_EXCL, SHM_FILE_MODE); if (fd_shm >= 0) { + res = fchmod(fd_shm, SHM_FILE_MODE); + if (res == -1) { + close(fd_shm); + shm_unlink(shm_name); + LOGE(TEEC_LIB, "Cannot change permission of the %s shared memory file, error: %s", + shm_name, strerror(errno)); + return TEEC_ERROR_GENERIC; + } break; } if (errno != EEXIST) { - umask(origMask); LOGE(TEEC_LIB, "Cannot create shared memory object, error: %s", strerror(errno)); return TEEC_ERROR_GENERIC; } @@ -122,8 +127,6 @@ static int32_t allocateSharedMemory(TEEC_SharedMemory *shm) { memKey++; } while (memKey < SHM_MAX_ID); - umask(origMask); - if (memKey == SHM_MAX_ID) { LOGE(TEEC_LIB, "Cannot find free shared memory slot"); return TEEC_ERROR_GENERIC; -- 2.7.4 From 59eebd3432bfb4b5083fcf062f6086db35f6fcc5 Mon Sep 17 00:00:00 2001 From: Krzysztof Dynowski Date: Tue, 24 Oct 2017 11:03:59 +0200 Subject: [PATCH 12/16] SVACE: fix DEREF_OF_NULL* warning Change-Id: I7a9b30bcafea43a61addb0f2e8fd899717bce7e1 --- TEECLib/src/teec_api.c | 6 +++++ TEEStub/PropertyAccess/PropertyApi.cpp | 5 ++-- ssflib/dep/cryptocore/source/CC_API.c | 3 +-- ssflib/dep/cryptocore/source/base/cc_bignum.c | 35 +++++++++++++++++++-------- ssflib/dep/uci/source/uci_api.c | 5 +++- ssflib/src/ssf_crypto.cpp | 11 +++++++-- ssflib/src/ssf_taentrypoint.cpp | 5 +++- 7 files changed, 52 insertions(+), 18 deletions(-) diff --git a/TEECLib/src/teec_api.c b/TEECLib/src/teec_api.c index 0860520..8c18e21 100644 --- a/TEECLib/src/teec_api.c +++ b/TEECLib/src/teec_api.c @@ -727,6 +727,9 @@ TEEC_Result TEEC_RegisterSharedMemory(TEEC_Context *context, sharedMem->imp = (TEEC_SharedMemoryImp*)OsaMalloc( sizeof(TEEC_SharedMemoryImp)); + if (sharedMem->imp == NULL) { + return TEE_ERROR_OUT_OF_MEMORY; + } TEEC_SharedMemoryImp* sharedMem_imp = (TEEC_SharedMemoryImp*)sharedMem->imp; sharedMem_imp->context = context; regmem.contextID = context_imp->contextID; @@ -839,6 +842,9 @@ TEEC_Result TEEC_AllocateSharedMemory(TEEC_Context *context, // Generate Shared Memory imp structure sharedMem->imp = (TEEC_SharedMemoryImp*)OsaMalloc( sizeof(TEEC_SharedMemoryImp)); + if (sharedMem->imp == NULL) { + return TEE_ERROR_OUT_OF_MEMORY; + } TEEC_SharedMemoryImp* sharedMem_imp = (TEEC_SharedMemoryImp*)sharedMem->imp; sharedMem->buffer = NULL; sharedMem_imp->context = context; diff --git a/TEEStub/PropertyAccess/PropertyApi.cpp b/TEEStub/PropertyAccess/PropertyApi.cpp index 60f1199..9b85dc1 100644 --- a/TEEStub/PropertyAccess/PropertyApi.cpp +++ b/TEEStub/PropertyAccess/PropertyApi.cpp @@ -410,9 +410,10 @@ uintptr_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator) { Property *targetProperty = NULL; PropertyEnumHandle *enumHandle = (PropertyEnumHandle*)propsetOrEnumerator; - if (enumHandle && enumHandle->property) + if (enumHandle && enumHandle->property) { targetProperty = enumHandle->property; - return targetProperty->propset; + return targetProperty->propset; + } } return 0; } diff --git a/ssflib/dep/cryptocore/source/CC_API.c b/ssflib/dep/cryptocore/source/CC_API.c index 8cb4f9f..03dad71 100644 --- a/ssflib/dep/cryptocore/source/CC_API.c +++ b/ssflib/dep/cryptocore/source/CC_API.c @@ -366,8 +366,7 @@ CryptoCoreContainer *create_CryptoCoreContainer(cc_u32 algorithm) // free CryptoCoreContainer data structure free(crt->ctx); free(crt); - crt = NULL; - break; + return NULL; } printf("TEST!!! after in create_CryptoCoreContainer(%p %d)\n",crt, ID_AES128); diff --git a/ssflib/dep/cryptocore/source/base/cc_bignum.c b/ssflib/dep/cryptocore/source/base/cc_bignum.c index f36508b..d9175ec 100644 --- a/ssflib/dep/cryptocore/source/base/cc_bignum.c +++ b/ssflib/dep/cryptocore/source/base/cc_bignum.c @@ -1608,12 +1608,15 @@ int SDRM_BN_Div(SDRM_BIG_NUM *BN_Quotient, SDRM_BIG_NUM *BN_Remainder, SDRM_BIG_ return CRYPTO_SUCCESS; } + tmp = 0; if (BN_Quotient == NULL) { - BN_Remainder->Length = temp_Divisor->Length; - tmp = SDRM_DWD_Div(bnTmp, BN_Remainder->pData, temp_Dividend->pData, temp_Dividend->Length, temp_Divisor->pData, temp_Divisor->Length); - SDRM_BN_OPTIMIZE_LENGTH(BN_Remainder); - BN_Remainder->sign = BN_Dividend->sign; + if (BN_Remainder != NULL) { + BN_Remainder->Length = temp_Divisor->Length; + tmp = SDRM_DWD_Div(bnTmp, BN_Remainder->pData, temp_Dividend->pData, temp_Dividend->Length, temp_Divisor->pData, temp_Divisor->Length); + SDRM_BN_OPTIMIZE_LENGTH(BN_Remainder); + BN_Remainder->sign = BN_Dividend->sign; + } } else if (BN_Remainder == NULL) { @@ -2852,6 +2855,9 @@ int SDRM_HEX2BN(cc_u8* pbSrc, SDRM_BIG_NUM *BN_Dst) //full string: bufferHex mod Length = 0 bufferHex = (cc_u8 *)malloc( sizeof(cc_u8) * (BN_Dst->Length * SDRM_SIZE_BLOCK)); + if (bufferHex == NULL) { + return CRYPTO_MEMORY_ALLOC_FAIL; + } //init byffer by 0 for(i = 0; i < BN_Dst->Length * SDRM_SIZE_BLOCK; i++) @@ -2992,6 +2998,11 @@ cc_u8 * SDRM_BN2STRBIN(cc_u32 *numberBits, SDRM_BIG_NUM *BN_Src) (*numberBits) = sizeof(cc_u8) * BN_Src->Length * SDRM_SIZE_OF_DWORD * 8 + 1; tempC = (cc_u8*)malloc(*numberBits); tempR = (cc_u8*)malloc(*numberBits); + if (tempC == NULL || tempR == NULL) { + free(tempR); + free(tempC); + return NULL; + } tempC[(*numberBits) - 1] = '\0'; for(i = BN_Src->Length - 1; (int)i >= 0 ; i--) { @@ -3104,7 +3115,7 @@ cc_u8 * SDRM_BN2STRFOUR(cc_u32 *numberBits, SDRM_BIG_NUM *BN_Src) } tempREM = SDRM_BN_Init(BN_Src->Size); num = SDRM_BN_Init(BN_Src->Size); - if( num == NULL)//fix prevent cid = 89093 by guoxing.xu + if(tempREM == NULL || num == NULL)//fix prevent cid = 89093 by guoxing.xu { free(strDestTemp); SDRM_BN_FREE(tempREM); @@ -3127,17 +3138,21 @@ cc_u8 * SDRM_BN2STRFOUR(cc_u32 *numberBits, SDRM_BIG_NUM *BN_Src) if((*numberBits) != 0) { strDest = (cc_u8*)malloc((*numberBits) + 1); - for(i = 0; i < (*numberBits); i++) { - strDest[i] = strDestTemp[((*numberBits) - 1) - i]; + if (strDest != NULL) { + for(i = 0; i < (*numberBits); i++) { + strDest[i] = strDestTemp[((*numberBits) - 1) - i]; + } + strDest[(*numberBits)] = '\0'; } - strDest[(*numberBits)] = '\0'; } else { (*numberBits) = 1; strDest = (cc_u8*)malloc((*numberBits) + 1); - strDest[0] = '0'; - strDest[(*numberBits)] = '\0'; + if (strDest != NULL) { + strDest[0] = '0'; + strDest[(*numberBits)] = '\0'; + } } free(strDestTemp); diff --git a/ssflib/dep/uci/source/uci_api.c b/ssflib/dep/uci/source/uci_api.c index c68357d..9ee995a 100644 --- a/ssflib/dep/uci/source/uci_api.c +++ b/ssflib/dep/uci/source/uci_api.c @@ -85,6 +85,9 @@ int uci_context_alloc(unsigned int algorithm, uci_engine_config_e config, UCI_HA #endif if (algorithm == ID_UCI_XCBCMAC) { ctx = (uci_context_s*)OsaMalloc(sizeof(uci_context_s)); + if (ctx == NULL) { + return UCI_ERROR; + } ctx->imp = (aes_xcbc_state *)OsaMalloc(sizeof(aes_xcbc_state)); ctx->alg = ID_UCI_XCBCMAC; *context = ctx; @@ -584,7 +587,7 @@ int uci_dup_handle(UCI_HANDLE srcoh, UCI_HANDLE* destoh) { uci_context_s *srcctx = (uci_context_s *)srcoh; uci_context_s *destctx = NULL; - if (destoh != NULL) { + if (destoh == NULL) { return UCI_ERROR; } diff --git a/ssflib/src/ssf_crypto.cpp b/ssflib/src/ssf_crypto.cpp index 7e4dda3..4020cdf 100644 --- a/ssflib/src/ssf_crypto.cpp +++ b/ssflib/src/ssf_crypto.cpp @@ -1146,7 +1146,9 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s } total_processing_len += processing_len; out_size -= processing_len; - out_data = (unsigned char*)((unsigned long) out_data + processing_len); + if (out_data) { + out_data = (unsigned char*)((unsigned long) out_data + processing_len); + } operation->data_len = 0; } } @@ -1174,7 +1176,9 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s total_processing_len += processing_len; in_size -= processing_len; in_data = (unsigned char*)((unsigned long) in_data + processing_len); - out_data = (unsigned char*)((unsigned long) out_data + processing_len); + if (out_data) { + out_data = (unsigned char*)((unsigned long) out_data + processing_len); + } } if (operation->info.mode == TEE_MODE_ENCRYPT) @@ -1239,6 +1243,9 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s } else if (operation->info.mode == TEE_MODE_DECRYPT) { unsigned char * pad = out_data; unsigned int npad = 0; + if (pad == NULL) { + goto exit; + } if (operation->info.algorithm == TEE_ALG_AES_ECB_NOPAD || operation->info.algorithm == TEE_ALG_AES_CBC_NOPAD || operation->info.algorithm == TEE_ALG_DES_ECB_NOPAD || operation->info.algorithm == TEE_ALG_DES_CBC_NOPAD || diff --git a/ssflib/src/ssf_taentrypoint.cpp b/ssflib/src/ssf_taentrypoint.cpp index 5b66369..ac9c859 100644 --- a/ssflib/src/ssf_taentrypoint.cpp +++ b/ssflib/src/ssf_taentrypoint.cpp @@ -87,6 +87,10 @@ TEE_Result TEE_OpenTASession(const TEE_UUID* destination, if (!session || !destination) { return TEE_ERROR_BAD_PARAMETERS; } + uint32_t* sessionData = (uint32_t*)OsaMalloc(sizeof(uint32_t)); + if (sessionData == NULL) { + return TEE_ERROR_OUT_OF_MEMORY; + } memset(&data, 0, sizeof(IntTAOpenSessionData)); data.source = ssf_sharedthisTAUUID; data.destination = *destination; @@ -119,7 +123,6 @@ TEE_Result TEE_OpenTASession(const TEE_UUID* destination, // [inout] TEE_Param params[4], // [out] TEE_TASessionHandle* session, // [out] uint32_t* returnOrigin); - uint32_t* sessionData = (uint32_t*)OsaMalloc(sizeof(uint32_t)); if(params != NULL) { __TEE_Postprocess_Operation; -- 2.7.4 From efaed2173de54163757450100c885d9c29c665bc Mon Sep 17 00:00:00 2001 From: Krzysztof Dynowski Date: Tue, 24 Oct 2017 11:39:58 +0200 Subject: [PATCH 13/16] SVAVE: fix INVARIANT_RESULT.OP_ASSIGN, NULL_AFTER_DEREF Change-Id: I9b5a4854f2ad9ff703e036425f7ccf09ea45c888 --- TEEStub/PropertyAccess/PropertyApi.cpp | 7 ++++--- ssflib/dep/cryptocore/source/base/cc_bignum.c | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/TEEStub/PropertyAccess/PropertyApi.cpp b/TEEStub/PropertyAccess/PropertyApi.cpp index 9b85dc1..2a52fdf 100644 --- a/TEEStub/PropertyAccess/PropertyApi.cpp +++ b/TEEStub/PropertyAccess/PropertyApi.cpp @@ -351,9 +351,10 @@ void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator, } } - newEnumHandle->property->setPropSet((uintptr_t)propSet); - if (newEnumHandle && newEnumHandle->property) - newEnumHandle->property->start(); + if (newEnumHandle && newEnumHandle->property) { + newEnumHandle->property->setPropSet((uintptr_t)propSet); + newEnumHandle->property->start(); + } } void TEE_ResetPropertyEnumerator(TEE_PropSetHandle enumerator) { diff --git a/ssflib/dep/cryptocore/source/base/cc_bignum.c b/ssflib/dep/cryptocore/source/base/cc_bignum.c index d9175ec..3d4a1b6 100644 --- a/ssflib/dep/cryptocore/source/base/cc_bignum.c +++ b/ssflib/dep/cryptocore/source/base/cc_bignum.c @@ -2879,7 +2879,7 @@ int SDRM_HEX2BN(cc_u8* pbSrc, SDRM_BIG_NUM *BN_Dst) { case '0': BN_Dst->pData[i] = BN_Dst->pData[i] << 4; - BN_Dst->pData[i] |= 0x0; + //BN_Dst->pData[i] |= 0x0; Unnecessary break; case '1': BN_Dst->pData[i] = BN_Dst->pData[i] << 4; -- 2.7.4 From 4a7348c1ac1062230b10f12c10d407adf48c3751 Mon Sep 17 00:00:00 2001 From: Mariusz Domanski Date: Tue, 24 Oct 2017 10:56:28 +0200 Subject: [PATCH 14/16] WRONG_ARGUMENTS_ORDER - SVACE related fixes Change-Id: I873b75218372ea4e3396797c99a3e887701f818d --- ssflib/dep/uci/source/uci_api.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssflib/dep/uci/source/uci_api.c b/ssflib/dep/uci/source/uci_api.c index 9ee995a..7989065 100644 --- a/ssflib/dep/uci/source/uci_api.c +++ b/ssflib/dep/uci/source/uci_api.c @@ -289,7 +289,7 @@ int uci_se_decrypt_oneblock(UCI_HANDLE oh, unsigned char *plain_text, if (cipher_text == NULL || plain_text == NULL || user_key == NULL) { return UCI_ERROR; } - return cryptocore_se_decrypt_oneblock(oh, cipher_text, plain_text, user_key); + return cryptocore_se_decrypt_oneblock(oh, plain_text, cipher_text, user_key); } int uci_wbse_init(UCI_HANDLE oh, int flag, unsigned char *key, -- 2.7.4 From df52dcdecc32ad1d076c81392cf48735521a4aa4 Mon Sep 17 00:00:00 2001 From: Jaroslaw Pelczar Date: Tue, 24 Oct 2017 11:12:33 +0200 Subject: [PATCH 15/16] disconnectfromServer: fix socket fd validity condition Change-Id: I71e566e7c791cc5dd10724210a477a20f88ba5ad Signed-off-by: Jaroslaw Pelczar --- TEECLib/src/teec_connection.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TEECLib/src/teec_connection.c b/TEECLib/src/teec_connection.c index af623ea..5f51621 100644 --- a/TEECLib/src/teec_connection.c +++ b/TEECLib/src/teec_connection.c @@ -86,7 +86,7 @@ void disconnectfromServer(int32_t serverSocket) { int32_t result; LOGD(TEEC_LIB, "Entry"); - if (serverSocket > 0) { + if (serverSocket >= 0) { // shutdown the socket result = shutdown(serverSocket, SHUT_WR); if (result != 0) -- 2.7.4 From 52e4d5015165757b24bda0d728e56bb6dcbc7fb5 Mon Sep 17 00:00:00 2001 From: Jaroslaw Pelczar Date: Tue, 24 Oct 2017 11:34:05 +0200 Subject: [PATCH 16/16] Fix error checking on msgctl() Change-Id: I53fcdb05c3567e12b42a2ad7a11536e875f972cf Signed-off-by: Jaroslaw Pelczar --- osal/OsaQueue.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osal/OsaQueue.c b/osal/OsaQueue.c index c1b5c16..ec9cc1f 100644 --- a/osal/OsaQueue.c +++ b/osal/OsaQueue.c @@ -449,7 +449,11 @@ int OsaQueueSetinfo(unsigned int uiQid, void* pvBuf) { data_t = (struct QueueInfo*)pvBuf; - msgctl((int)uiQid, IPC_STAT, &buf); + if(msgctl((int)uiQid, IPC_STAT, &buf) < 0) { + perror("In OsaQueueGetinfo() : msgctl: msgctl failed"); + return ((int)errno); + } + buf.msg_qbytes = data_t->maxlen; if (msgctl((int)uiQid, IPC_SET, &buf) < 0) { -- 2.7.4