Enable -Werror flag, fix warnings and 64-bit build 73/149573/1
authorLukasz Kostyra <l.kostyra@samsung.com>
Tue, 12 Sep 2017 09:18:38 +0000 (11:18 +0200)
committerLukasz Kostyra <l.kostyra@samsung.com>
Tue, 12 Sep 2017 12:53:29 +0000 (14:53 +0200)
Change-Id: I97c215c91efb2627d93cb98e321c9e6a8875f722

23 files changed:
CMakeLists.txt
TEEStub/PropertyAccess/Property.h
TEEStub/PropertyAccess/PropertyApi.cpp
TEEStub/PropertyAccess/PropertyUtility.cpp
TEEStub/TACommands/SharedMemoryMap.cpp
log/log.h
osal/OsaIpc.c
osal/OsaSem.c
osal/OsaTask.c
osal/Osal.h
ssflib/dep/swdss/include/ss_types.h
ssflib/dep/swdss/source/secure_file.cpp
ssflib/dep/uci/include/uci_api.h
ssflib/dep/uci/include/uci_cryptocore.h
ssflib/dep/uci/include/uci_hwcrypto.h
ssflib/dep/uci/include/uci_type.h
ssflib/dep/uci/source/uci_api.c
ssflib/dep/uci/source/uci_cryptocore.c
ssflib/dep/uci/source/uci_hwcrypto.c
ssflib/inc/crypto_internal.h
ssflib/src/ssf_crypto.cpp
ssflib/src/ssf_crypto_openssl.cpp
ssflib/src/ssf_storage.cpp

index 8444fd0..3c8ff86 100644 (file)
@@ -43,7 +43,7 @@ ADD_DEFINITIONS("-D_GNU_SOURCE")
 
 # Set compiler warning flags
 # TODO uncomment these when it's cleanup time
-#ADD_DEFINITIONS("-Werror")                      # Make all warnings into errors.
+ADD_DEFINITIONS("-Werror")                      # Make all warnings into errors.
 #ADD_DEFINITIONS("-Wall")                        # Generate all warnings
 #ADD_DEFINITIONS("-Wextra")                      # Generate even more extra warnings
 
index bdfa950..6ca8f29 100644 (file)
@@ -45,7 +45,7 @@ public:
        virtual bool start() = 0;\r
        virtual void reset() = 0;\r
        virtual bool getPropertyValue(PropertyValue&) = 0;\r
-       void setPropSet(unsigned int propset) {\r
+       void setPropSet(uintptr_t propset) {\r
                this->propset = propset;\r
        };\r
        Property() {\r
@@ -54,7 +54,7 @@ public:
        virtual ~Property() {\r
        }\r
        ;\r
-       unsigned int propset;\r
+       uintptr_t propset;\r
 };\r
 \r
 #endif /* PROPERTYACCESS_PROPERTY_H_ */\r
index cb858ea..3a5c437 100644 (file)
@@ -48,7 +48,7 @@ bool _allowPropertyAccess = false;
  * @return NULL if handle is invalid else returns valid handle\r
  */\r
 static Property* _GetTargetProperty(TEE_PropSetHandle propsetOrEnumerator);\r
-static uint32_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator);\r
+static uintptr_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator);\r
 \r
 //GLOBAL DEFNS\r
 typedef struct {\r
@@ -101,7 +101,7 @@ void DeInitPropertyModule() {
 \r
 string getQueryProp(TEE_PropSetHandle propsetOrEnumerator, string name) {\r
        size_t pos;\r
-       uint32_t propSet = _GetTargetPropsetType(propsetOrEnumerator);\r
+       uintptr_t propSet = _GetTargetPropsetType(propsetOrEnumerator);\r
        if(propSet == TEE_PROPSET_CURRENT_TA &&\r
                (pos = name.rfind(".")) != string::npos) {\r
                return name.substr(pos + 1);\r
@@ -316,7 +316,7 @@ void TEE_FreePropertyEnumerator(TEE_PropSetHandle enumerator) {
 void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator,\r
     TEE_PropSetHandle propSet) {\r
        PropertyEnumHandle *newEnumHandle = (PropertyEnumHandle*)enumerator;\r
-       switch ((uint32_t)propSet) {\r
+       switch ((uintptr_t)propSet) {\r
                case TEE_PROPSET_CURRENT_TA: {\r
                        newEnumHandle->property = new TAProperty(\r
                            string(TEE_TASTORE_ROOT) + thisTAUUIDGlobal + "-ext/"\r
@@ -330,7 +330,7 @@ void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator,
                        if(!_allowPropertyAccess)\r
                        {\r
                                break;\r
-                       }                                       \r
+                       }\r
                        newEnumHandle->property = new ClientProperty(pv);\r
                        break;\r
                }\r
@@ -344,7 +344,7 @@ void TEE_StartPropertyEnumerator(TEE_PropSetHandle enumerator,
                }\r
        }\r
 \r
-       newEnumHandle->property->setPropSet((uint32_t)propSet);\r
+       newEnumHandle->property->setPropSet((uintptr_t)propSet);\r
        if (newEnumHandle && newEnumHandle->property)\r
                newEnumHandle->property->start();\r
 }\r
@@ -388,12 +388,12 @@ TEE_Result TEE_GetNextProperty(TEE_PropSetHandle enumerator) {
        } else return TEE_ERROR_ITEM_NOT_FOUND;\r
 }\r
 \r
-uint32_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator) {\r
-       switch ((uint32_t)propsetOrEnumerator) {\r
+uintptr_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator) {\r
+       switch ((uintptr_t)propsetOrEnumerator) {\r
                case TEE_PROPSET_TEE_IMPLEMENTATION:\r
                case TEE_PROPSET_CURRENT_CLIENT:\r
                case TEE_PROPSET_CURRENT_TA:\r
-                       return (uint32_t)propsetOrEnumerator;\r
+                       return (uintptr_t)propsetOrEnumerator;\r
        }\r
        set<PropertyEnumHandle*>::iterator it =\r
                propertyEnumHandleSet.find((PropertyEnumHandle*)propsetOrEnumerator);\r
@@ -410,7 +410,7 @@ uint32_t _GetTargetPropsetType(TEE_PropSetHandle propsetOrEnumerator) {
 \r
 Property* _GetTargetProperty(TEE_PropSetHandle propsetOrEnumerator) {\r
        Property *targetProperty = NULL;\r
-       switch ((uint32_t)propsetOrEnumerator) {\r
+       switch ((uintptr_t)propsetOrEnumerator) {\r
                case TEE_PROPSET_TEE_IMPLEMENTATION: {\r
                        targetProperty = teeProperty;\r
                        break;\r
index 7a13f5a..0a711cf 100644 (file)
@@ -127,7 +127,7 @@ TEE_Result PropertyUtility::convertToUUID(const PropertyValue& in,
                string clockSeqStr = tokensString[4] + tokensString[5] + tokensString[6]\r
                    + tokensString[7];\r
                //TEST CODE: string clockSeqStr("0123456789ABCDEF");\r
-               sscanf(clockSeqStr.c_str(), "%16llx", &clockSeq);\r
+               clockSeq = std::stoll(clockSeqStr);\r
                memcpy(uuid.clockSeqAndNode, &clockSeq, sizeof(uint64_t));\r
                // Change endian-ness\r
                uint8_t temp[4];\r
index db31401..8864082 100644 (file)
@@ -84,7 +84,7 @@ bool SharedMemoryMap::isExist(uint32_t key, pRegisterItem reg)
 void* SharedMemoryMap::newOnceSharedMemory(uint32_t size) {
        static uint32_t add_value = 0;
        if(++add_value == 10000) add_value = 0;
-       srand(time(NULL) + add_value + (uint32_t)&size);
+       srand(time(NULL) + add_value + (uintptr_t)&size);
        uint32_t useKey = rand();
 
        //uint32_t useKey = (uint32_t)&size;
@@ -111,7 +111,7 @@ void* SharedMemoryMap::newOnceSharedMemory(uint32_t size) {
        size = (size + (PAGE_SIZE - 1)) & PAGE_MASK;
        void* buffer = (void*)shmat(shmid, NULL, 0);
        if (buffer == (void*)-1) {
-               LOGE(TEE_STUB, "shmat failed(%d(shmid:%d))",(int32_t)buffer, shmid);
+               LOGE(TEE_STUB, "shmat failed(%p(shmid:%d))", buffer, shmid);
                sharedResult = false;
        }
        if (!buffer) {
index db87ebc..ad0c409 100644 (file)
--- a/log/log.h
+++ b/log/log.h
 //#define _LOGGING
 
 #ifdef _WIN
-typedef int int8_t;
-typedef int int16_t;
-typedef int int32_t;
-typedef long long int int64_t;
-typedef long long unsigned uint64_t;
 typedef int timer_t;
 #endif
 
index 489f82b..bc9c19f 100644 (file)
@@ -132,7 +132,7 @@ typedef struct {
 #define MAX_NAMEDSEM_MGR 256
 
 static int UlOsaNamedSemCreate(const char pcName[10], int iCount,
-    int iAttribute, unsigned int* puiSmid) {
+    int iAttribute, void **puiSmid) {
        int iRetVal = OSAL_OK;
        UlOsaSem_t* sem;
        key_t semKey;
@@ -175,7 +175,7 @@ static int UlOsaNamedSemCreate(const char pcName[10], int iCount,
        memcpy((void*)sem->bName, (const void*)pcName, (size_t)10);
        sem->bName[10] = '\0';
 
-       *puiSmid = (unsigned int)sem;
+       *puiSmid = (void*)sem;
 
        return iRetVal;
 }
@@ -201,7 +201,7 @@ static int UlOsaNamedSemDelete(unsigned int uiSmid)
 }
 #endif
 
-static int UlOsaNamedSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
+static int UlOsaNamedSemGet(void *uiSmid, int iFlags, int iTimeout) {
        struct sembuf semBuf;
        struct timespec ts;
        struct timeval tv;
@@ -266,7 +266,7 @@ static int UlOsaNamedSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
        }
 
 }
-static int UlOsaNamedSemRelease(unsigned int uiSmid) {
+static int UlOsaNamedSemRelease(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
        struct sembuf semBuf;
 
@@ -287,7 +287,7 @@ static int UlOsaNamedSemRelease(unsigned int uiSmid) {
        }
 }
 
-static int UlOsaNamedSemReset(unsigned int uiSmid) {
+static int UlOsaNamedSemReset(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
        union semun semUnion;
 
@@ -305,7 +305,7 @@ static int UlOsaNamedSemReset(unsigned int uiSmid) {
        return OSAL_OK;
 }
 
-static int UlOsaNamedSemGetval(unsigned int uiSmid) {
+static int UlOsaNamedSemGetval(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
        int n;
 
@@ -323,28 +323,28 @@ static int UlOsaNamedSemGetval(unsigned int uiSmid) {
 }
 
 int OsaNamedSemCreate(const char bName[10], int iCount, int iAttribute,
-    unsigned int* puiSmid) {
+    void **puiSmid) {
        return UlOsaNamedSemCreate(bName, iCount, iAttribute, puiSmid);
 }
 
-int OsaNamedSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
+int OsaNamedSemGet(void *uiSmid, int iFlags, int iTimeout) {
        return UlOsaNamedSemGet(uiSmid, iFlags, iTimeout);
 }
 
-int OsaNamedSemRelease(unsigned int uiSmid) {
+int OsaNamedSemRelease(void *uiSmid) {
        return UlOsaNamedSemRelease(uiSmid);
 }
 
-int OsaNamedSemDelete(unsigned int uiSmid) { // Deleting Semaphore : Never USE!!! - junhyeong.kim, sukki.min 12.04.20
+int OsaNamedSemDelete(void *uiSmid) { // Deleting Semaphore : Never USE!!! - junhyeong.kim, sukki.min 12.04.20
 //return UlOsaNamedSemDelete (uiSmid);
        return -1;
 }
 
-int OsaNamedSemGetval(unsigned int uiSmid) {
+int OsaNamedSemGetval(void *uiSmid) {
        return UlOsaNamedSemGetval(uiSmid);
 }
 
-int OsaNamedSemReset(unsigned int uiSmid) {
+int OsaNamedSemReset(void *uiSmid) {
        return UlOsaNamedSemReset(uiSmid);
 }
 
index eaef3e1..5d07f31 100644 (file)
@@ -38,7 +38,7 @@ typedef struct _UlOsaSem {
 /* TODO: apply iAttribute */
 // COMMON_071008_1
 static int UlOsaSemCreate(const char bName[10], int iCount, int iAttribute,
-    unsigned int* puiSmid) {
+    void **puiSmid) {
        UlOsaSem_t* sem;
 
        sem = (UlOsaSem_t*)malloc(sizeof(*sem));
@@ -59,12 +59,12 @@ static int UlOsaSemCreate(const char bName[10], int iCount, int iAttribute,
        memcpy((void*)sem->bName, (const void*)bName, (size_t)10);
        sem->bName[10] = '\0';
 
-       *puiSmid = (unsigned int)sem;
+       *puiSmid = (void*)sem;
 
        return OSAL_OK;
 }
 
-static int UlOsaSemDelete(unsigned int uiSmid) {
+static int UlOsaSemDelete(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
 
        if (!sem) {
@@ -77,7 +77,7 @@ static int UlOsaSemDelete(unsigned int uiSmid) {
        return OSAL_OK;
 }
 
-static int UlOsaSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
+static int UlOsaSemGet(void *uiSmid, int iFlags, int iTimeout) {
        int ret;
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
 
@@ -147,7 +147,7 @@ static int UlOsaSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
        }
 }
 
-static int UlOsaSemRelease(unsigned int uiSmid) {
+static int UlOsaSemRelease(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
        if (!sem) {
                return OSAL_ERROR;
@@ -162,7 +162,7 @@ static int UlOsaSemRelease(unsigned int uiSmid) {
        }
 }
 
-static int UlOsaSemReset(unsigned int uiSmid) {
+static int UlOsaSemReset(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
        if (!sem) {
                return OSAL_ERROR;
@@ -182,7 +182,7 @@ static int UlOsaSemReset(unsigned int uiSmid) {
        return OSAL_OK;
 }
 
-static int UlOsaSemGetval(unsigned int uiSmid) {
+static int UlOsaSemGetval(void *uiSmid) {
        UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
        int n;
        if (!sem) {
@@ -201,14 +201,14 @@ static int UlOsaSemGetval(unsigned int uiSmid) {
 /**
  * @brief      Create a semaphore object.
  * @remarks    the semaphore value shall be incremented more than initial value.
- * @param      bName [in] semaphore name, for debugging.               
- * @param      iCount [in] initial semaphore value                     
+ * @param      bName [in] semaphore name, for debugging.
+ * @param      iCount [in] initial semaphore value
  * @param      iAttribute [in] not used now implementation.
  * @param      puiSmid [out] semaphore object ID.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
 int OsaSemCreate(const char bName[10], int iCount, int iAttribute,
-    unsigned int* puiSmid) {
+    void **puiSmid) {
        /* OSA_070901 */
        return UlOsaSemCreate(bName, iCount, iAttribute, puiSmid);
 }
@@ -219,7 +219,7 @@ int OsaSemCreate(const char bName[10], int iCount, int iAttribute,
  * @param      uiSmid [in] semaphore object ID created by OsaSemCreate.
  * @param      iFlags [in] [OSAL_SEM_NOWAIT | OSAL_SEM_WAIT]
  - OSAL_SEM_NOWAIT : lock the semaphore only if the semaphore value is
- currently not locked. otherwise, return OSAL_ERROR.                           
+ currently not locked. otherwise, return OSAL_ERROR.
  - OSAL_SEM_WAIT : lock the semaphore. If the semaphore values is
  currently locked, the calling thread shall be blocked.
  In linux kernel mode, iFlags is not used, always wait infinitely.
@@ -230,7 +230,7 @@ int OsaSemCreate(const char bName[10], int iCount, int iAttribute,
  - negative value : error.
  * @retval     [OSAL_OK | OSAL_ERROR | OSAL_ERR_TIMEOUT]
  */
-int OsaSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
+int OsaSemGet(void *uiSmid, int iFlags, int iTimeout) {
        /* OSA_070901 */
        return UlOsaSemGet(uiSmid, iFlags, iTimeout);
 }
@@ -242,7 +242,7 @@ int OsaSemGet(unsigned int uiSmid, int iFlags, int iTimeout) {
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemRelease(unsigned int uiSmid) {
+int OsaSemRelease(void *uiSmid) {
        /* OSA_070901 */
        return UlOsaSemRelease(uiSmid);
 }
@@ -253,7 +253,7 @@ int OsaSemRelease(unsigned int uiSmid) {
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemDelete(unsigned int uiSmid) {
+int OsaSemDelete(void *uiSmid) {
        /* OSA_070901 */
        return UlOsaSemDelete(uiSmid);
 }
@@ -265,7 +265,7 @@ int OsaSemDelete(unsigned int uiSmid) {
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemGetval(unsigned int uiSmid) {
+int OsaSemGetval(void *uiSmid) {
        /* OSA_070901 */
        return UlOsaSemGetval(uiSmid);
 }
@@ -280,7 +280,7 @@ int OsaSemGetval(unsigned int uiSmid) {
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemReset(unsigned int uiSmid) {
+int OsaSemReset(void *uiSmid) {
        /* OSA_070901 */
        return UlOsaSemReset(uiSmid);
 }
@@ -288,20 +288,20 @@ int OsaSemReset(unsigned int uiSmid) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      : OsaMutCreate 
- // Detail Description : This function is used to creat a mutex.  
+ // Function Name      : OsaMutCreate
+ // Detail Description : This function is used to creat a mutex.
  //              Mutex attributes can be either "Fast" mutex, "Recursive
  //              mutexes or "Error checking " mutex .
- //              piMutid is the pointer to the new mutex ID created else 
- //              is NULL. 
- //              
+ //              piMutid is the pointer to the new mutex ID created else
+ //              is NULL.
+ //
  // Return Data Type   : ErrorType
  //
  // Programming Note   : None.
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaMutCreate(const char bName[10], int iAttributes, unsigned int* puiMutid) {
+int OsaMutCreate(const char bName[10], int iAttributes, void **puiMutid) {
        pthread_mutexattr_t attr_t;
        pthread_mutex_t* pmutex_t;
 
@@ -328,7 +328,7 @@ int OsaMutCreate(const char bName[10], int iAttributes, unsigned int* puiMutid)
                                break;
                }
 
-               (*puiMutid) = (unsigned int)pmutex_t;
+               (*puiMutid) = (void*)pmutex_t;
 
                pthread_mutexattr_destroy(&attr_t);
        } else {
@@ -342,10 +342,10 @@ int OsaMutCreate(const char bName[10], int iAttributes, unsigned int* puiMutid)
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      : OsaMutDelete  
+ // Function Name      : OsaMutDelete
  // Detail Description : This function deletes the Mutex with corresponding
  //              mutex ID .
- //              This function deallocates any system resources allocated 
+ //              This function deallocates any system resources allocated
  //              by the system for use by this task for this Mutex.
  //
  // Return Data Type   : ErrorType
@@ -355,7 +355,7 @@ int OsaMutCreate(const char bName[10], int iAttributes, unsigned int* puiMutid)
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaMutDelete(unsigned int uiMutid) {
+int OsaMutDelete(void *uiMutid) {
        int iRet;
 
        pthread_mutex_t* pmutex_t = (pthread_mutex_t *)uiMutid;
@@ -377,17 +377,17 @@ int OsaMutDelete(unsigned int uiMutid) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      : OsaMutRelease  
- // Detail Description : This function unlocks the mutex.  
+ // Function Name      : OsaMutRelease
+ // Detail Description : This function unlocks the mutex.
  //
  // Return Data Type   : ErrorType
  //
- // Programming Note   : None  
+ // Programming Note   : None
  //
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaMutRelease(unsigned int uiMutid) {
+int OsaMutRelease(void *uiMutid) {
        int iRet;
 
        pthread_mutex_t* pmutex_t = (pthread_mutex_t *)uiMutid;
@@ -403,8 +403,8 @@ int OsaMutRelease(unsigned int uiMutid) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      : OsaMutGet  
- // Detail Description : This function locks the mutex.  
+ // Function Name      : OsaMutGet
+ // Detail Description : This function locks the mutex.
  //
  // Return Data Type   : ErrorType
  //
@@ -412,7 +412,7 @@ int OsaMutRelease(unsigned int uiMutid) {
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaMutGet(unsigned int uiMutid, int iFlags, int iTimeout) {
+int OsaMutGet(void *uiMutid, int iFlags, int iTimeout) {
        int iRet;
        pthread_mutex_t* pmutex_t = (pthread_mutex_t *)uiMutid;
        iRet = pthread_mutex_lock(pmutex_t);
@@ -435,7 +435,7 @@ int OsaMutGet(unsigned int uiMutid, int iFlags, int iTimeout) {
 // Programming Note   : None.
 //------------------------------------------------------------------------------
 // $$$
-int OsaMutTryGet(unsigned int uiMutid, int iFlags, int iTimeout) {
+int OsaMutTryGet(void *uiMutid, int iFlags, int iTimeout) {
        int iRet;
 
        pthread_mutex_t* pmutex_t = (pthread_mutex_t *)uiMutid;
index 492a437..6decac2 100644 (file)
@@ -74,7 +74,7 @@ static void* _thread_start_handler(void* pArg) {
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
+int OsaTaskSpawn(const char* pName, void **puiTid, int iPriority,
     int iStacksize, unsigned int uiMode, void* pEntryPt, int iArg1, int iArg2,
     int iArg3, int iArg4, void* pvArg5) {
 
@@ -121,7 +121,7 @@ int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
                iRet = pthread_create(&createThread, (pthread_attr_t *)NULL,
                    _thread_start_handler, (void*)pThreadParam);
                if (iRet) {
-                       *puiTid = (unsigned int)NULL;
+                       *puiTid = NULL;
                        free(pThreadParam);
                        perror("In OsaTaskSpawn() :  pthread create Failed\n ");
                        //PrintError("In OsaTaskSpawn() : error no. : %d\n", iRet);
@@ -132,7 +132,7 @@ int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
        else {
                iRet = pthread_attr_init(&tattr_t);
                if (iRet) {
-                       *puiTid = (unsigned int)NULL;
+                       *puiTid = NULL;
                        free(pThreadParam);
                        perror("In OsaTaskSpawn() : pthread attr init  Failed\n ");
                        //PrintError("In OsaTaskSpawn() : error no. : %d\n", iRet);
@@ -140,7 +140,7 @@ int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
                }
                iRet = pthread_attr_setstacksize(&tattr_t, (unsigned int)iStacksize);
                if (iRet) {
-                       *puiTid = (unsigned int)NULL;
+                       *puiTid = NULL;
                        free(pThreadParam);
                        perror("In OsaTaskSpawn() : pthread attr setstacksize Failed\n ");
                        //PrintError("In OsaTaskSpawn() : error no. : %d\n", iRet);
@@ -150,7 +150,7 @@ int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
                iRet = pthread_create(&createThread, (pthread_attr_t *)&tattr_t,
                    _thread_start_handler, (void*)pThreadParam);
                if (iRet) {
-                       *puiTid = (unsigned int)NULL;
+                       *puiTid = NULL;
                        free(pThreadParam);
                        perror("In OsaTaskSpawn() :  pthread create Failed\n ");
                        //PrintError("In OsaTaskSpawn() : error no. : %d\n", iRet);
@@ -166,23 +166,23 @@ int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
                param_t.__sched_priority = iPriority;
                iRet = pthread_setschedparam(createThread, createThreadPolicy, &param_t);
                if (iRet) {
-                       *puiTid = (unsigned int)NULL;
+                       *puiTid = NULL;
                        perror("In OsaTaskSpawn() :  pthread setschedparam Failed\n ");
                        //PrintError("In OsaTaskSpawn() : error no. : %d\n", iRet);
-                       pthread_kill(createThread, (int)NULL);
+                       pthread_kill(createThread, 0);
                        return ((int)iRet);
                }
        }
 
        iRet = pthread_detach(createThread);
        if (iRet) {
-               *puiTid = (unsigned int)NULL;
+               *puiTid = NULL;
                perror("In OsaTaskSpawn() :  pthread_detach Failed\n ");
                //PrintError("In OsaTaskSpawn() : detach error no. : %d\n", iRet);
-               pthread_kill(createThread, (int)NULL);
+               pthread_kill(createThread, 0);
                return ((int)iRet);
        }
-       *puiTid = (unsigned int)createThread;
+       *puiTid = (void*)createThread;
 
        //PrintDbg("%s thread created policy: %d, priority %d\n", pName, createThreadPolicy, iPriority);
        return OSAL_OK;
@@ -191,12 +191,12 @@ int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      :       OsaExit 
+ // Function Name      :       OsaExit
  // Detail Description : This function terminates the calling thread.
  //
  // Return Data Type   : Void
  //
- // Programming Note   : None. 
+ // Programming Note   : None.
  //------------------------------------------------------------------------------
  // $$$
  */
@@ -207,9 +207,9 @@ void OsaExit(int iStatus) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      :       OsaTaskDelete 
- // Detail Description : This function terminates the thread having the 
- //                            corresponding thread ID .  
+ // Function Name      :       OsaTaskDelete
+ // Detail Description : This function terminates the thread having the
+ //                            corresponding thread ID .
  //
  // Return Data Type   : ErrorType
  //
@@ -217,7 +217,7 @@ void OsaExit(int iStatus) {
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaTaskDelete(unsigned int uiTid) {
+int OsaTaskDelete(void *uiTid) {
        int iRet = 0;
        iRet = pthread_cancel((pthread_t)uiTid);
        if (iRet) {
@@ -231,12 +231,12 @@ int OsaTaskDelete(unsigned int uiTid) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      :       OsaTaskSetPriority 
+ // Function Name      :       OsaTaskSetPriority
  // Detail Description : This function sets the Priority for the created thread.
  //
  // Return Data Type   : ErrorType
  //
- // Programming Note   : None.  
+ // Programming Note   : None.
  //------------------------------------------------------------------------------
  // $$$
  */
@@ -260,9 +260,9 @@ int OsaTaskSetPriority(unsigned int uiTid, int iNewpriority) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      : OsaTaskGetPriority 
+ // Function Name      : OsaTaskGetPriority
  // Detail Description : This function gets the corresponding priority of the
- //                            supplied thread ID .  
+ //                            supplied thread ID .
  //
  // Return Data Type   : ErrorType
  //
@@ -288,9 +288,9 @@ int OsaTaskGetPriority(unsigned int uiTid, int* piPriority) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      :       OsaTaskNanosleep 
+ // Function Name      :       OsaTaskNanosleep
  // Detail Description : This function makes the thread to sleep for nanosec
- //                    precision.  
+ //                    precision.
  //
  // Return Data Type   :       ErrorType
  //
@@ -326,8 +326,8 @@ int OsaTaskNanosleep(int iNanosec) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      :       OsaTaskGetId 
- // Detail Description : This function get the current thread ID.  
+ // Function Name      :       OsaTaskGetId
+ // Detail Description : This function get the current thread ID.
  //
  // Return Data Type   : Current thread ID .
  //
@@ -342,9 +342,9 @@ int OsaTaskGetId(void) {
 /*
  // $$$
  //-----------------------------------------------------------------------------
- // Function Name      :       OsaTaskDelaymsecs 
+ // Function Name      :       OsaTaskDelaymsecs
  // Detail Description : This function makes the thread to sleep for millisec
- //                    precision.  
+ //                    precision.
  //
  // Return Data Type   :       ErrorType
  //
index d7ef083..e56ad14 100644 (file)
@@ -33,7 +33,7 @@ extern "C"
 
 #include <signal.h>
 #include <sys/ipc.h>
-#include <mqueue.h> 
+#include <mqueue.h>
 
 #endif
 
@@ -68,16 +68,16 @@ extern "C"
 #if defined(__KERNEL__)
 #define OSA_Q_NOWAIT           0x1
 #define OSA_Q_WAIT                     0x2
-#elif defined(POSIX_QUEUE) //user mode, posix queue                            
-#define OSA_Q_NOWAIT           O_NONBLOCK                      
-#define OSA_Q_WAIT                     0x00                                    
+#elif defined(POSIX_QUEUE) //user mode, posix queue
+#define OSA_Q_NOWAIT           O_NONBLOCK
+#define OSA_Q_WAIT                     0x00
 #elif defined(__NO_OS__)
 #define OSA_Q_NOWAIT 0
 #define OSA_Q_WAIT 0
 #else  //user mode, system v ipc
 #define OSA_Q_NOWAIT           IPC_NOWAIT
 #define OSA_Q_WAIT                     0x00
-#endif 
+#endif
 
 #define OSAL_ERR_TIMEOUT       0x37
 #define OSAL_ERR_NOMSG         0x01
@@ -86,12 +86,12 @@ extern "C"
 #define OSAL_TIMER_ONESHOT     0
 #define OSAL_NSEC_MAX          999999999
 
-#if defined(__KERNEL__) // Linux kernel mode 
+#if defined(__KERNEL__) // Linux kernel mode
 #define OSAL_MIN_STSZ          (16*1024)       /*kthread min statck size*/
 #else // Linux user mode
 #undef  PTHREAD_STACK_MIN              ///* PTHREAD_STACK_MIN is defined in <pthread.h>, It's configure stack limit in  pthread
 #define PTHREAD_STACK_MIN      (16*1024)
-#define OSAL_MIN_STSZ          PTHREAD_STACK_MIN       
+#define OSAL_MIN_STSZ          PTHREAD_STACK_MIN
 #endif
 
 #define OSAL_MAX_STSZ          (16*1024)
@@ -99,7 +99,7 @@ extern "C"
 #define OSAL_DEFAULT_PRIORITY  0
 
 #define MAXNBM                         1024    //5
-#define MAXML                          8192    
+#define MAXML                          8192
 #define OSAL_DEFAULT_Q_NUM     1
 #define OSAL_DEFAULT_Q_LEN     1
 
@@ -122,7 +122,7 @@ extern "C"
 #define OSAL_SEM_NOWAIT        0
 #define OSAL_DEFAULT_SEMVAL    1
 
-// Signal 
+// Signal
 #define OSAL_SIG_BLOCK         SIG_BLOCK
 #define OSAL_SIG_UNBLOCK       SIG_UNBLOCK
 #define OSAL_SIG_SETMASK       SIG_SETMASK
@@ -137,7 +137,7 @@ extern "C"
                        }
 #else
 #define OSAL_ASSERT(expression) assert(expression)
-#endif 
+#endif
 
 /*-----------------------------------------------------------------------------
  *  Globals
@@ -172,32 +172,32 @@ typedef struct _cache_io_param {
 /*-----------------------------------------------------------------------------
  *  Functions
  *-----------------------------------------------------------------------------*/
-int OsaTaskSpawn(const char* pName, unsigned int* puiTid, int iPriority,
+int OsaTaskSpawn(const char* pName, void **puiTid, int iPriority,
     int iStacksize, unsigned int uiMode, void* pvEntryPt, int iArg1, int iArg2,
     int iArg3, int iArg4, void* pvArg5);
 
 /* stop a running thread (called by "killer") */
-int OsaTaskDelete(unsigned int uiTid);
+int OsaTaskDelete(void *uiTid);
 
 /* cleanup thread environment (called by thread upon receiving termination signal) */
-void OsaExitKthread(voidpvArg);
+void OsaExitKthread(void *pvArg);
 
 /* setup thread environment (called by new thread) */
-void OsaInitKthread(voidpvArg);
+void OsaInitKthread(void *pvArg);
 
 int OsaTaskGetId(void);
 
 /**
  * @brief      Create a semaphore object.
  * @remarks    the semaphore value shall be incremented more than initial value.
- * @param      bName [in] semaphore name, for debugging.               
- * @param      iCount [in] initial semaphore value                     
+ * @param      bName [in] semaphore name, for debugging.
+ * @param      iCount [in] initial semaphore value
  * @param      iAttribute [in] not used now implementation.
  * @param      puiSmid [out] semaphore object ID.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
 int OsaSemCreate(const char bName[10], int iCount, int iAttribute,
-    unsigned int* puiSmid); // COMMON_071008_1
+    void **puiSmid); // COMMON_071008_1
 
 /**
  * @brief      Lock a semaphore.
@@ -205,7 +205,7 @@ int OsaSemCreate(const char bName[10], int iCount, int iAttribute,
  * @param      uiSmid [in] semaphore object ID created by OsaSemCreate.
  * @param      iFlags [in] [OSAL_SEM_NOWAIT | OSAL_SEM_WAIT]
  - OSAL_SEM_NOWAIT : lock the semaphore only if the semaphore value is
- currently not locked. otherwise, return OSAL_ERROR.                           
+ currently not locked. otherwise, return OSAL_ERROR.
  - OSAL_SEM_WAIT : lock the semaphore. If the semaphore values is
  currently locked, the calling thread shall be blocked.
  In linux kernel mode, iFlags is not used, always wait infinitely.
@@ -216,7 +216,7 @@ int OsaSemCreate(const char bName[10], int iCount, int iAttribute,
  - negative value : error.
  * @retval     [OSAL_OK | OSAL_ERROR | OSAL_ERR_TIMEOUT]
  */
-int OsaSemGet(unsigned int uiSmid, int iFlags, int iTimeout);
+int OsaSemGet(void *uiSmid, int iFlags, int iTimeout);
 
 /**
  * @brief      Unlock a semaphore
@@ -225,7 +225,7 @@ int OsaSemGet(unsigned int uiSmid, int iFlags, int iTimeout);
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemRelease(unsigned int uiSmid);
+int OsaSemRelease(void *uiSmid);
 
 /**
  * @brief      Destroy a semaphore object.
@@ -233,7 +233,7 @@ int OsaSemRelease(unsigned int uiSmid);
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemDelete(unsigned int uiSmid);
+int OsaSemDelete(void *uiSmid);
 
 /**
  * @brief      Get the current semaphore value
@@ -242,7 +242,7 @@ int OsaSemDelete(unsigned int uiSmid);
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemGetval(unsigned int uiSmid);
+int OsaSemGetval(void *uiSmid);
 
 /**
  * @brief      Reset the semaphore to initial state.
@@ -254,16 +254,16 @@ int OsaSemGetval(unsigned int uiSmid);
  * @param      uiSmid [id] semaphore object ID created by OsaSemCreate.
  * @retval     [OSAL_OK | OSAL_ERROR]
  */
-int OsaSemReset(unsigned int uiSmid);
+int OsaSemReset(void *uiSmid);
 
 //Mutex
-int OsaMutCreate(const char bName[10], int iAttributes, unsigned int* pvArg);
+int OsaMutCreate(const char bName[10], int iAttributes, void **pvArg);
 
-int OsaMutDelete(unsigned int uiSmid);
+int OsaMutDelete(void *uiSmid);
 
-int OsaMutRelease(unsigned int uiSmid);
+int OsaMutRelease(void *uiSmid);
 
-int OsaMutGet(unsigned int uiSmid, int iFlags, int iTimeout);
+int OsaMutGet(void *uiSmid, int iFlags, int iTimeout);
 
 //Queue
 int OsaQueueCreate(const char name[10], unsigned int flags, unsigned int maxnum,
@@ -443,13 +443,12 @@ int OsaShmDetach(const void *pShmAddr);
  //------------------------------------------------------------------------------
  // $$$
  */
-int OsaNamedSemCreate(const char pName[10], int iCount, int iAttribute,
-    unsigned int* puiSemId);
-int OsaNamedSemGet(unsigned int uiSemId, int iFlags, int iTimeout);
-int OsaNamedSemRelease(unsigned int uiSemId);
-int OsaNamedSemDelete(unsigned int uiSemId);
-int OsaNamedSemGetval(unsigned int uiSemId);
-int OsaNamedSemReset(unsigned int uiSemId);
+int OsaNamedSemCreate(const char pName[10], int iCount, int iAttribute, void **puiSemId);
+int OsaNamedSemGet(void *uiSemId, int iFlags, int iTimeout);
+int OsaNamedSemRelease(void *uiSemId);
+int OsaNamedSemDelete(void *uiSemId);
+int OsaNamedSemGetval(void *uiSemId);
+int OsaNamedSemReset(void *uiSemId);
 
 #ifdef __cplusplus
 }
index 02f1791..275cf38 100644 (file)
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License. 
+ * limitations under the License.
  */
 
 #ifndef _SWD_SS_COMMON_H_
 #define _SWD_SS_COMMON_H_
 
+#include <stdint.h>
+
 #define SS_MAX_UUID_LEN 64
 #define SS_MAX_MODULE_NAME_LEN 32
 #define SS_MAX_DATA_NAME_LEN 128
@@ -84,16 +86,12 @@ typedef struct credential {
 
 } ss_credential_s;
 
-typedef unsigned char uint8_t;
-typedef unsigned int uint32_t;
-typedef unsigned long long uint64_t;
 typedef uint8_t CBT_OCTET;
 typedef uint8_t* CBT_OCTET_PTR;
 typedef uint32_t CBT_UINT32;
 typedef uint32_t* CBT_UINT32_PTR;
 typedef void* CBT_DATA_PTR;
 typedef CBT_UINT32 CBT_BOOL;
-typedef unsigned short uint16_t;
 
 #endif
 
index d004504..9e4c0bd 100644 (file)
@@ -430,7 +430,7 @@ uint64_t secure_file::transform_id_to_name(uint64_t uDataFileID) {
        // hexidecimal representation of return value will be the real file name.
        uDataFileName = uDataFileName1 | (((uint64_t)uDataFileName2) << 32);
 
-       SLOGI("[%s][%d] uDataFileName : %lu", __FUNCTION__, __LINE__, uDataFileName);
+       SLOGI("[%s][%d] uDataFileName : %llu", __FUNCTION__, __LINE__, (unsigned long long)uDataFileName);
        return uDataFileName;
 }
 
index a5d6a65..ebf40ee 100644 (file)
@@ -39,14 +39,14 @@ extern "C" {
 /**
  * @brief allocates memory and initializes the cryptographic context structure, and return the crypto handle..
  *
- * @param[in] algorithm, algorithm wants to use.
- * @config[in] config, config specified which function to call.
- * @retval UCI handle  if success
- * @retval UCI_ERROR if fail
+ * @param[in] algorithm algorithm wants to use.
+ * @param[in] config config specified which function to call.
+ * @param[out] context handle to created context
+ * @retval UCI_SUCCESS if successful
+ * @retval UCI_ERROR if failed
  * @retval UCI_MEM_ALLOR_ERROR if allocate memory error.
  */
-UCI_HANDLE uci_context_alloc(unsigned int algorithm,
-    uci_engine_config_e config);
+int uci_context_alloc(unsigned int algorithm, uci_engine_config_e config, UCI_HANDLE* context);
 
 /**
  * @brief free allocated memory.
@@ -147,9 +147,9 @@ int uci_mac_final(UCI_HANDLE oh, unsigned char *output,
  * @retval UCI_INVALID_HANDLE   if oh is invalid handle.
  * @retval UCI_ERROR    Other error. such key is NULL or msg is NULL.
  */
-int uci_mac_get_mac(UCI_HANDLE oh, unsigned char *key, unsigned int key_len,
-    unsigned char * msg, unsigned int msg_len, unsigned char * output,
-    size_t *output_len);
+ int uci_mac_get_mac(UCI_HANDLE oh, unsigned char *key, unsigned int key_len,
+    unsigned char *msg, unsigned int msg_len, unsigned char *output,
+    unsigned int *output_len);
 
 /**
  * @brief    initialize crypt context for symmetric cryptography
@@ -327,8 +327,8 @@ int uci_ae_decrypt(UCI_HANDLE oh, unsigned char * input, unsigned int input_len,
  * @retval UCI_MSG_TOO_LONG    the input_len is too long. The correct usage is that input_len shorter than key length.
  * @retvla UCI_ERROR   input or output is NULL.
  */
-int uci_ae_decryptbycrt(UCI_HANDLE oh, unsigned char * input,
-    unsigned int input_len, unsigned char * output, size_t* output_len);
+ int uci_ae_decryptbycrt(UCI_HANDLE oh, unsigned char *input,
+    unsigned int input_len, unsigned char *output, unsigned int *output_len);
 
 /**
  * @brief    whitebox rsa encryption
@@ -435,7 +435,7 @@ int uci_prng_seed(UCI_HANDLE oh, unsigned char * seed);
  */
 int uci_prng_get(UCI_HANDLE oh, unsigned int bit_len, unsigned char *data);
 
-int uci_dup_handle(UCI_HANDLE srcoh, UCI_HANDLE destoh);
+int uci_dup_handle(UCI_HANDLE srcoh, UCI_HANDLE* destoh);
 int uci_authcrypt_init(UCI_HANDLE oh, unsigned int mode, unsigned char *nonce,
     unsigned int nonce_len, unsigned int tag_len, unsigned int aad_len,
     unsigned int payload_len, unsigned char *key, unsigned int key_len);
index ab40685..3ac27de 100644 (file)
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License. 
+ * limitations under the License.
  */
 
-/** 
- * @file uci_cryptocore.h 
- * @brief UCI codec. 
- * @author guoxing.xu 
- * @version 1.0 
+/**
+ * @file uci_cryptocore.h
+ * @brief UCI codec.
+ * @author guoxing.xu
+ * @version 1.0
  * @date 2013.7
  **/
 #ifndef _UCI_CRYPTOCORE_H
 
 #ifdef __cplusplus
 extern "C" {
-#endif  
+#endif
 
 /**
  * @brief allocates memory and initializes the cryptographic context structure, and return the crypto handle..
  *
- * @param[in] algorithm, algorithm wants to use.
- * @retval UCI handle  if success  
- * @retval UCI_ERROR if fail
+ * @param[in] algorithm algorithm to be used
+ * @param[out] context returned handle to cryptocore context
+ * @retval UCI_SUCCESS on success
+ * @retval UCI_ERROR if failed
  */
-UCI_HANDLE cryptocore_context_alloc(unsigned int algorithm);
+int cryptocore_context_alloc(unsigned int algorithm, UCI_HANDLE* context);
+
 /**
  * @brief free allocated memory.
  *
- * @param[in] algorithm algorithm wants to use. 
+ * @param[in] algorithm algorithm wants to use.
  * @retval UCI_SUCCESS  If no error occurred.
  * @retval UCI_INVALID_HANDLE   If oh is not a valid handle.
  */
@@ -59,17 +61,17 @@ int cryptocore_md_init(UCI_HANDLE oh);
  * @brief      process a message block
  * @param[in] oh    UCI operator handle.
  * @param[in] msg   message.
- * @param[in] msglen    byte-length of msg.    
+ * @param[in] msglen    byte-length of msg.
  * @UCI_SUCCESS If no error occurred.
  * @UCI_INVALID_HANDLE  If oh is not a valid handle.
  */
 int cryptocore_md_update(UCI_HANDLE oh, unsigned char *msg,
     unsigned int msg_len);
 
-/**    
+/**
  * @brief      get hashed message
  * @param[in]   oh UCI operator handle
- * @param[out] output   hashed message.        
+ * @param[out] output   hashed message.
  * @   retval UCI_SUCCESS  If no error occurred.
  * @   retval UCI_INVALID_HANDLE   If oh is not a valid handle.
  */
@@ -81,7 +83,7 @@ int cryptocore_md_final(UCI_HANDLE oh, unsigned char * output);
  * @param[in] oh UCI operator handle
  * @param[in] msg    message
  * @param[in] msglen byte-length of msg
- * @param[out] output    hashed message.       
+ * @param[out] output    hashed message.
  * @   retval UCI_SUCCESS  If no error occurred.
  * @   retval UCI_INVALID_HANDLE   If oh is not a valid handle.
  */
@@ -254,7 +256,7 @@ int cryptocore_ae_gen_keypair(UCI_HANDLE oh, uci_key_s* keymaterial,
 int cryptocore_ae_set_keypair(UCI_HANDLE oh, uci_key_s* keymaterial,
     uci_param_s* param);
 
-/**    
+/**
  * @brief      RSA Encryption
  * @param[in] oh    UCI handle
  * @param[in] input message to encrypt
index 02a7710..1d2b717 100644 (file)
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
- * limitations under the License. 
+ * limitations under the License.
  */
 
-/** 
- * @file uci_hwcrypto.h 
- * @brief hwcrypto codec. 
- * @author guoxing.xu 
- * @version 1.0 
+/**
+ * @file uci_hwcrypto.h
+ * @brief hwcrypto codec.
+ * @author guoxing.xu
+ * @version 1.0
  * @date 2013.7
  **/
 #ifndef _UCI_HWCRYPTO_H
 
 #ifdef __cplusplus
 extern "C" {
-#endif  
+#endif
 
 /**
  * @brief allocates memory and initializes the cryptographic context structure, and return the crypto handle..
  *
- * @param[in] algorithm, algorithm wants to use.
- * @retval UCI handle  if success  
+ * @param[in] algorithm algorithm wants to use
+ * @param[in] config configuration to be used
+ * @param[out] context created context handle
+ * @retval UCI_SUCCESS on success
  * @retval UCI_ERROR if fail
  */
-UCI_HANDLE hwcrypto_context_alloc(unsigned int algorithm,
-    uci_engine_config_e config);
+int hwcrypto_context_alloc(unsigned int algorithm, uci_engine_config_e config, UCI_HANDLE* context);
 
 /**
  * @brief free allocated memory.
  *
- * @param[in] algorithm algorithm wants to use. 
+ * @param[in] algorithm algorithm wants to use.
  * @retval UCI_SUCCESS  If no error occurred.
  * @retval UCI_INVALID_HANDLE   If oh is not a valid handle.
  */
@@ -103,7 +104,7 @@ int hwcrypto_se_final(UCI_HANDLE oh, unsigned char *input,
 
 #ifdef __cplusplus
 }
-#endif  
+#endif
 
 #endif
 
index 89bcb13..840dfef 100644 (file)
@@ -35,7 +35,7 @@
  * @brief  UCI handle.
  *
  */
-typedef int UCI_HANDLE;
+typedef void* UCI_HANDLE;
 /**
  * @brief UCI return error type.
  *
index 238cda9..656de1e 100644 (file)
        TC_PRINT("\n");                                                                         \
 }
 
-UCI_HANDLE uci_context_alloc(unsigned int algorithm, uci_engine_config_e config) {
+int uci_context_alloc(unsigned int algorithm, uci_engine_config_e config, UCI_HANDLE* context) {
        unsigned int conf = SDRM_LOW_HALF(config);
        uci_context_s *ctx;
 
+       if (context == NULL) {
+               return UCI_ERROR;
+       }
        if (algorithm < ID_UCI_X931 || algorithm > ID_UCI_AE_CCM) {
                return UCI_ERROR;
        }
@@ -83,13 +86,14 @@ UCI_HANDLE uci_context_alloc(unsigned int algorithm, uci_engine_config_e config)
                ctx = (uci_context_s*)OsaMalloc(sizeof(uci_context_s));
                ctx->imp = (aes_xcbc_state *)OsaMalloc(sizeof(aes_xcbc_state));
                ctx->alg = ID_UCI_XCBCMAC;
-               return (int)ctx;
+               *context = ctx;
+               return UCI_SUCCESS;
        }
        if (conf == UCI_SW_CRYPTOCORE) {
-               return cryptocore_context_alloc(algorithm);
+               return cryptocore_context_alloc(algorithm, context);
        }
        if (conf == UCI_HW) {
-               return hwcrypto_context_alloc(algorithm, config);
+               return hwcrypto_context_alloc(algorithm, config, context);
        }
 
        return UCI_ERROR;
@@ -575,11 +579,20 @@ int uci_authcrypt_decryptfinal(UCI_HANDLE oh, unsigned char *src,
        return UCI_ERROR;
 }
 
-int uci_dup_handle(UCI_HANDLE srcoh, UCI_HANDLE destoh) {
+int uci_dup_handle(UCI_HANDLE srcoh, UCI_HANDLE* destoh) {
        uci_context_s *srcctx = (uci_context_s *)srcoh;
        uci_context_s *destctx = NULL;
-       destoh = uci_context_alloc(srcctx->alg, (uci_engine_config_e)srcctx->config);
-       destctx = (uci_context_s *)destoh;
+
+       if (destoh != NULL) {
+               return UCI_ERROR;
+       }
+
+       int ret = uci_context_alloc(srcctx->alg, (uci_engine_config_e)srcctx->config, destoh);
+       if (ret != UCI_SUCCESS) {
+               return ret;
+       }
+
+       destctx = (uci_context_s *)(*destoh);
        if (destctx == NULL) {
                return UCI_ERROR;
        }
index 573613b..74f7ed4 100644 (file)
 #define TZ_ERROR(fmt...) \
                do {if (g_bTAdbug) printf("[SSFLIB] ");printf(fmt);}while(0)
 
-UCI_HANDLE cryptocore_context_alloc(unsigned int algorithm) {
-       UCI_HANDLE fd;
+int cryptocore_context_alloc(unsigned int algorithm, UCI_HANDLE* context) {
        uci_context_s* ctx;
        CryptoCoreContainer *crt;
 
+       if (context == NULL) {
+               return UCI_ERROR;
+       }
+
        ctx = (uci_context_s*)OsaMalloc(sizeof(uci_context_s));
        if (ctx == NULL) {
                return UCI_MEM_ALLOR_ERROR;
        }
-       fd = (UCI_HANDLE)ctx;
+
        crt = create_CryptoCoreContainer(algorithm);
        if (crt == NULL) {
                OsaFree(ctx);
@@ -50,8 +53,8 @@ UCI_HANDLE cryptocore_context_alloc(unsigned int algorithm) {
        ctx->imp = (void*)crt;
        ctx->config = UCI_SW;
        ctx->alg = algorithm;
-       return fd;
-
+       *context = ctx;
+       return UCI_SUCCESS;
 }
 
 int cryptocore_context_free(UCI_HANDLE oh) {
index ff15c41..2862c1d 100644 (file)
@@ -15,7 +15,7 @@
 */
 #define PC_I586
 
-/** 
+/**
 * @file uci_hwcrypto.cpp
 * @brief UCI codec.
 * @author guoxing.xu
 
 #define g_bTAdbug 0
 #define TA_PRINT(fmt...) \
-    do {if (g_bTAdbug) printf(fmt);}while(0)
+       do {if (g_bTAdbug) printf(fmt);}while(0)
 #define TA_ERROR(fmt...) \
-    do {if (g_bTAdbug) printf(fmt);}while(0)
+       do {if (g_bTAdbug) printf(fmt);}while(0)
 
 /*! \brief  convert 32-bit unit to 4 byte   */
 #undef GET_UINT32
 #define GET_UINT32(n,b,i)                                                              \
-        {                                                       \
-            (n) = ((unsigned int)((b)[(i)    ]) << 24 )         \
-                | ((unsigned int)((b)[(i) + 1]) << 16 )         \
-                | ((unsigned int)((b)[(i) + 2]) <<  8 )         \
-                | ((unsigned int)((b)[(i) + 3])       );        \
-        }
-
-UCI_HANDLE  hwcrypto_context_alloc(unsigned int algorithm, uci_engine_config_e config)
+               {                                                       \
+                       (n) = ((unsigned int)((b)[(i)    ]) << 24 )         \
+                               | ((unsigned int)((b)[(i) + 1]) << 16 )         \
+                               | ((unsigned int)((b)[(i) + 2]) <<  8 )         \
+                               | ((unsigned int)((b)[(i) + 3])       );        \
+               }
+
+int hwcrypto_context_alloc(unsigned int algorithm, uci_engine_config_e config, UCI_HANDLE* context)
 {
+       uci_context_s* ctx;
 
-    UCI_HANDLE fd;
-    uci_context_s* ctx;
-    ctx = (uci_context_s*)malloc(sizeof(uci_context_s));
-    if(ctx == NULL)
-    {
-        return UCI_MEM_ALLOR_ERROR;
-    }
-    ctx->config = config;
-    ctx->alg    = algorithm;
+       if (context == NULL)
+       {
+               return UCI_ERROR;
+       }
+
+       ctx = (uci_context_s*)malloc(sizeof(uci_context_s));
+       if(ctx == NULL)
+       {
+               return UCI_MEM_ALLOR_ERROR;
+       }
+
+       ctx->config = config;
+       ctx->alg    = algorithm;
 #ifndef PC_I586
-    ctx->imp    = malloc(sizeof(struct crypt_info));
+       ctx->imp    = malloc(sizeof(struct crypt_info));
 #else
-    ctx->imp    = create_CryptoCoreContainer(algorithm);
+       ctx->imp    = create_CryptoCoreContainer(algorithm);
 #endif
        if(ctx->imp == NULL)
        {
-           free(ctx);
+               free(ctx);
                return UCI_MEM_ALLOR_ERROR;
        }
-       fd = (UCI_HANDLE)ctx;
-    return fd;
+
+       *context = ctx;
+       return UCI_SUCCESS;
 }
 
 int hwcrypto_context_free( UCI_HANDLE  oh )
 {
-    uci_context_s *pctx = (uci_context_s*)oh;
-    if(pctx == NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    if(pctx->imp != NULL)
-    {
+       uci_context_s *pctx = (uci_context_s*)oh;
+       if(pctx == NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       if(pctx->imp != NULL)
+       {
 #ifndef PC_I586
-        free(pctx->imp);
+               free(pctx->imp);
 #else
-        destroy_CryptoCoreContainer((CryptoCoreContainer*)pctx->imp);
+               destroy_CryptoCoreContainer((CryptoCoreContainer*)pctx->imp);
 #endif
-        pctx->imp = NULL;
-    }
+               pctx->imp = NULL;
+       }
 #ifndef PC_I586
-    /*close crypto handle*/
-    if(pctx->handle >= 0)
-    {
-        close(pctx->handle);
-    }
+       /*close crypto handle*/
+       if(pctx->handle >= 0)
+       {
+               close(pctx->handle);
+       }
 #endif
-    free(pctx);
-    pctx = NULL;
-    return UCI_SUCCESS;
+       free(pctx);
+       pctx = NULL;
+       return UCI_SUCCESS;
 }
 
 int hwcrypto_se_init(UCI_HANDLE  oh, unsigned int mode, unsigned int  padding, unsigned char *key, unsigned int key_len, unsigned char *iv)
 {
 #ifndef PC_I586
-    uci_context_s      *pctx;
-    struct crypt_info  *info;
-    unsigned int keytype;
-    int ret = 0;
-    pctx = (uci_context_s*)oh;
-    if(pctx == NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    info = (struct crypt_info*)pctx->imp;
-    keytype = SDRM_HIGH_HALF(pctx->config);
-
-
-    if(keytype == UCI_USER_KEY && key == NULL)
-    {
-        return UCI_ERROR;
-    }
-
-    switch(pctx->alg)
-    {
-        case ID_UCI_AES128:
-            switch(mode)
-            {
-                case ID_UCI_ENC_CBC:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_CBC_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_CBC;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_CBC;
-                    break;
-                case ID_UCI_ENC_CTR:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_CTR_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_CTR;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_CTR;
-                    break;
-                case ID_UCI_ENC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_ECB_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_ECB;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_ECB;
-                    break;
-                case ID_UCI_DEC_CBC:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_CBC_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_CBC | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_CBC;
-                    break;
-                case ID_UCI_DEC_CTR:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_CTR_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_CTR | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_CTR;
-                    break;
-                case ID_UCI_DEC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_ECB_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_ECB | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_ECB;
-                    break;
-                default:
-                    return UCI_INVALID_ARGUMENT;
-            }
-            info->keylen = 16;
-            info->ivlen = 16;
-            break;
-        case ID_UCI_AES256:/*now only support ecb and ctr*/
-            switch(mode)
-            {
-                case ID_UCI_ENC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_ECB_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_ECB;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_ECB;
-                    break;
-                case ID_UCI_DEC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_ECB_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_ECB | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_ECB;
-                    break;
-                case ID_UCI_ENC_CTR:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_CTR_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_CTR;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_CTR;
-                    break;
-                case ID_UCI_DEC_CTR:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_AES_CTR_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_AES_CTR | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_CTR;
-                    break;
-                default:
-                    return UCI_INVALID_ARGUMENT;
-            }
-            info->keylen = 32;
-            info->ivlen = 16;
-            break;
-        case ID_UCI_DES:
-            switch(mode)
-            {
-                case ID_UCI_ENC_CBC:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_DES_CBC_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_DES_CBC;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_CBC;
-                    break;
-                case ID_UCI_ENC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_DES_ECB_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_DES_ECB;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_ECB;
-                    break;
-                case ID_UCI_DEC_CBC:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_DES_CBC_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_DES_CBC | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_CBC;
-                    break;
-                case ID_UCI_DEC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_DES_ECB_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_DES_ECB | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_ECB;
-                    break;
-                default:
-                    return UCI_INVALID_ARGUMENT;
-
-            }
-            info->keylen = 8;
-            info->ivlen = 8;
-            break;
-        case ID_UCI_TDES:
-            switch(mode)
-            {
-                case ID_UCI_ENC_CBC:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_TDES_CBC_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_TDES_CBC;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_CBC;
-                    break;
-                case ID_UCI_ENC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_TDES_ECB_PAD;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_TDES_ECB;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_ECB;
-                    break;
-                case ID_UCI_DEC_CBC:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_TDES_CBC_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_TDES_CBC | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_ENC_ECB;
-                    break;
-                case ID_UCI_DEC_ECB:
-                    if(padding == ID_UCI_PKCS5)
-                    {
-                        info->mode = MI_TDES_ECB_PAD | _MODE_DEC_;
-                    }
-                    else if(padding == ID_UCI_NO_PADDING)
-                    {
-                        info->mode = MI_TDES_ECB | _MODE_DEC_;
-                    }
-                    else
-                    {
-                        return UCI_INVALID_ARGUMENT;
-                    }
-                    pctx->mode = ID_UCI_DEC_ECB;
-                    break;
-                default:
-                    return UCI_INVALID_ARGUMENT;
-
-            }
-            info->keylen = 24;
-            info->ivlen = 8;
-            break;
-        default:
-            return UCI_INVALID_HANDLE;
-
-    }
-
-    /*set info key*/
-
-    switch(keytype)
-    {
-        case UCI_USER_KEY:
-            info->keytype = KEYID_USER_KEY;
-            if(key_len != 8 && key_len != 16 && key_len != 24 && key_len != 32)
-            {
-                return UCI_INVALID_ARGUMENT;
-            }
-            memcpy(info->key, key, key_len);
-            break;
-        case UCI_SECRET_KEY:
-            info->keytype = KEYID_SECURE_KEY;
-            break;
-        case UCI_MASTER_KEY:
-            info->keytype = KEYID_MASTER_KEY;
-            break;
-        default :
-            return UCI_INVALID_ARGUMENT;
-    }
-    /*setiv*/
-    if(iv)
-    {
-        memcpy(info->iv, iv, info->ivlen);
-    }
-    else
-    {
-        memset(info->iv, 0x0, info->ivlen);
-    }
-    pctx->handle = open("/dev/crypto", 0, 0 ); //return hndl;
-    //TA_PRINT("hand = %d \n",pctx->handle);
-    if(pctx->handle < 0)
-    {
-        return UCI_ERROR;
-    }
-    if (ret = ioctl(pctx->handle, IOCTL_CRYPTO_INIT, info))
-    {
-        TA_PRINT("error:ioctl(hndl, IOCTL_CRYPTO_INIT, info) returned %d\n",ret);
-        return UCI_ERROR;
-    }
-    return UCI_SUCCESS;
+       uci_context_s      *pctx;
+       struct crypt_info  *info;
+       unsigned int keytype;
+       int ret = 0;
+       pctx = (uci_context_s*)oh;
+       if(pctx == NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       info = (struct crypt_info*)pctx->imp;
+       keytype = SDRM_HIGH_HALF(pctx->config);
+
+
+       if(keytype == UCI_USER_KEY && key == NULL)
+       {
+               return UCI_ERROR;
+       }
+
+       switch(pctx->alg)
+       {
+               case ID_UCI_AES128:
+                       switch(mode)
+                       {
+                               case ID_UCI_ENC_CBC:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_CBC_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_CBC;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_CBC;
+                                       break;
+                               case ID_UCI_ENC_CTR:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_CTR_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_CTR;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_CTR;
+                                       break;
+                               case ID_UCI_ENC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_ECB_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_ECB;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_ECB;
+                                       break;
+                               case ID_UCI_DEC_CBC:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_CBC_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_CBC | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_CBC;
+                                       break;
+                               case ID_UCI_DEC_CTR:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_CTR_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_CTR | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_CTR;
+                                       break;
+                               case ID_UCI_DEC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_ECB_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_ECB | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_ECB;
+                                       break;
+                               default:
+                                       return UCI_INVALID_ARGUMENT;
+                       }
+                       info->keylen = 16;
+                       info->ivlen = 16;
+                       break;
+               case ID_UCI_AES256:/*now only support ecb and ctr*/
+                       switch(mode)
+                       {
+                               case ID_UCI_ENC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_ECB_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_ECB;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_ECB;
+                                       break;
+                               case ID_UCI_DEC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_ECB_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_ECB | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_ECB;
+                                       break;
+                               case ID_UCI_ENC_CTR:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_CTR_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_CTR;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_CTR;
+                                       break;
+                               case ID_UCI_DEC_CTR:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_AES_CTR_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_AES_CTR | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_CTR;
+                                       break;
+                               default:
+                                       return UCI_INVALID_ARGUMENT;
+                       }
+                       info->keylen = 32;
+                       info->ivlen = 16;
+                       break;
+               case ID_UCI_DES:
+                       switch(mode)
+                       {
+                               case ID_UCI_ENC_CBC:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_DES_CBC_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_DES_CBC;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_CBC;
+                                       break;
+                               case ID_UCI_ENC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_DES_ECB_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_DES_ECB;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_ECB;
+                                       break;
+                               case ID_UCI_DEC_CBC:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_DES_CBC_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_DES_CBC | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_CBC;
+                                       break;
+                               case ID_UCI_DEC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_DES_ECB_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_DES_ECB | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_ECB;
+                                       break;
+                               default:
+                                       return UCI_INVALID_ARGUMENT;
+
+                       }
+                       info->keylen = 8;
+                       info->ivlen = 8;
+                       break;
+               case ID_UCI_TDES:
+                       switch(mode)
+                       {
+                               case ID_UCI_ENC_CBC:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_TDES_CBC_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_TDES_CBC;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_CBC;
+                                       break;
+                               case ID_UCI_ENC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_TDES_ECB_PAD;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_TDES_ECB;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_ECB;
+                                       break;
+                               case ID_UCI_DEC_CBC:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_TDES_CBC_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_TDES_CBC | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_ENC_ECB;
+                                       break;
+                               case ID_UCI_DEC_ECB:
+                                       if(padding == ID_UCI_PKCS5)
+                                       {
+                                               info->mode = MI_TDES_ECB_PAD | _MODE_DEC_;
+                                       }
+                                       else if(padding == ID_UCI_NO_PADDING)
+                                       {
+                                               info->mode = MI_TDES_ECB | _MODE_DEC_;
+                                       }
+                                       else
+                                       {
+                                               return UCI_INVALID_ARGUMENT;
+                                       }
+                                       pctx->mode = ID_UCI_DEC_ECB;
+                                       break;
+                               default:
+                                       return UCI_INVALID_ARGUMENT;
+
+                       }
+                       info->keylen = 24;
+                       info->ivlen = 8;
+                       break;
+               default:
+                       return UCI_INVALID_HANDLE;
+
+       }
+
+       /*set info key*/
+
+       switch(keytype)
+       {
+               case UCI_USER_KEY:
+                       info->keytype = KEYID_USER_KEY;
+                       if(key_len != 8 && key_len != 16 && key_len != 24 && key_len != 32)
+                       {
+                               return UCI_INVALID_ARGUMENT;
+                       }
+                       memcpy(info->key, key, key_len);
+                       break;
+               case UCI_SECRET_KEY:
+                       info->keytype = KEYID_SECURE_KEY;
+                       break;
+               case UCI_MASTER_KEY:
+                       info->keytype = KEYID_MASTER_KEY;
+                       break;
+               default :
+                       return UCI_INVALID_ARGUMENT;
+       }
+       /*setiv*/
+       if(iv)
+       {
+               memcpy(info->iv, iv, info->ivlen);
+       }
+       else
+       {
+               memset(info->iv, 0x0, info->ivlen);
+       }
+       pctx->handle = open("/dev/crypto", 0, 0 ); //return hndl;
+       //TA_PRINT("hand = %d \n",pctx->handle);
+       if(pctx->handle < 0)
+       {
+               return UCI_ERROR;
+       }
+       if (ret = ioctl(pctx->handle, IOCTL_CRYPTO_INIT, info))
+       {
+               TA_PRINT("error:ioctl(hndl, IOCTL_CRYPTO_INIT, info) returned %d\n",ret);
+               return UCI_ERROR;
+       }
+       return UCI_SUCCESS;
 
 #else
 
-    int ret = UCI_ERROR;
-    uci_context_s *pctx = (uci_context_s*)oh;
-    unsigned int keytype;
-    unsigned int alg;
-         //!AS current hw is not ready, so using SW pseduo way temproray.
-    unsigned char hwkey_master[32]={ 0xAB, 0x12, 0x45, 0x67, 0x3F, 0x80, 0x98, 0x35,
-                                     0x06, 0x4F, 0x33, 0x39, 0x72, 0x1C, 0xDF, 0x23,
-                                     0xAB, 0x12, 0x45, 0x67, 0x3F, 0x80, 0x98, 0x35,
-                                     0x06, 0x4F, 0x33, 0x39, 0x72, 0x1C, 0xDF, 0x23};
-    unsigned char hwiv_master[16] ={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
-                                     0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
-    unsigned char hwkey_unique[32]={ 0xF0, 0x22, 0x34, 0x67, 0x66, 0x88, 0xAB, 0xCD,
-                                     0x12, 0x67, 0x89, 0x54, 0x32, 0x10, 0xCC, 0xFE,
-                                     0xAB, 0x12, 0x45, 0x67, 0x3F, 0x80, 0x98, 0x35,
-                                     0x06, 0x4F, 0x33, 0x39, 0x72, 0x1C, 0xDF, 0x23};
-    unsigned char hwiv_unique[16] ={ 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88,
-                                     0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
-    if(pctx == NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    alg = pctx->alg;
-    switch(alg)
-    {
-        case ID_UCI_AES128:
-            key_len = 16;
-            break;
-        case ID_UCI_AES256:
-            key_len = 32;
-            break;
-        case ID_UCI_DES:
-            key_len = 8;
-            break;
-        case ID_UCI_TDES:
-            key_len = 24;
-
-    }
-    keytype = SDRM_HIGH_HALF(pctx->config);
-    if (keytype != UCI_USER_KEY)
-    {
-        if(keytype == UCI_MASTER_KEY)
-        {
-            ret = ((CryptoCoreContainer *)pctx->imp)->SE_init((CryptoCoreContainer *)pctx->imp, mode, padding, hwkey_master,key_len,hwiv_master);
-
-        }
-        else if(keytype == UCI_SECRET_KEY)
-        {
-            ret =((CryptoCoreContainer *)pctx->imp)->SE_init((CryptoCoreContainer *)pctx->imp, mode, padding, hwkey_unique,key_len,hwiv_unique);
-        }
-    }
-    else
-    {
-        ret = ((CryptoCoreContainer *)pctx->imp)->SE_init((CryptoCoreContainer *)pctx->imp, mode, padding, key,key_len, iv);
-
-    }
-
-    if(ret == CRYPTO_INVALID_ARGUMENT)
-    {
-        return UCI_INVALID_ARGUMENT;
-    }
-    if(ret != CRYPTO_SUCCESS)
-    {
-        return UCI_ERROR;
-    }
-
-    return UCI_SUCCESS;
+       int ret = UCI_ERROR;
+       uci_context_s *pctx = (uci_context_s*)oh;
+       unsigned int keytype;
+       unsigned int alg;
+                //!AS current hw is not ready, so using SW pseduo way temproray.
+       unsigned char hwkey_master[32]={ 0xAB, 0x12, 0x45, 0x67, 0x3F, 0x80, 0x98, 0x35,
+                                                                        0x06, 0x4F, 0x33, 0x39, 0x72, 0x1C, 0xDF, 0x23,
+                                                                        0xAB, 0x12, 0x45, 0x67, 0x3F, 0x80, 0x98, 0x35,
+                                                                        0x06, 0x4F, 0x33, 0x39, 0x72, 0x1C, 0xDF, 0x23};
+       unsigned char hwiv_master[16] ={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
+                                                                        0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
+       unsigned char hwkey_unique[32]={ 0xF0, 0x22, 0x34, 0x67, 0x66, 0x88, 0xAB, 0xCD,
+                                                                        0x12, 0x67, 0x89, 0x54, 0x32, 0x10, 0xCC, 0xFE,
+                                                                        0xAB, 0x12, 0x45, 0x67, 0x3F, 0x80, 0x98, 0x35,
+                                                                        0x06, 0x4F, 0x33, 0x39, 0x72, 0x1C, 0xDF, 0x23};
+       unsigned char hwiv_unique[16] ={ 0xFF, 0xEE, 0xDD, 0xCC, 0xBB, 0xAA, 0x99, 0x88,
+                                                                        0x77, 0x66, 0x55, 0x44, 0x33, 0x22, 0x11, 0x00};
+       if(pctx == NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       alg = pctx->alg;
+       switch(alg)
+       {
+               case ID_UCI_AES128:
+                       key_len = 16;
+                       break;
+               case ID_UCI_AES256:
+                       key_len = 32;
+                       break;
+               case ID_UCI_DES:
+                       key_len = 8;
+                       break;
+               case ID_UCI_TDES:
+                       key_len = 24;
+
+       }
+       keytype = SDRM_HIGH_HALF(pctx->config);
+       if (keytype != UCI_USER_KEY)
+       {
+               if(keytype == UCI_MASTER_KEY)
+               {
+                       ret = ((CryptoCoreContainer *)pctx->imp)->SE_init((CryptoCoreContainer *)pctx->imp, mode, padding, hwkey_master,key_len,hwiv_master);
+
+               }
+               else if(keytype == UCI_SECRET_KEY)
+               {
+                       ret =((CryptoCoreContainer *)pctx->imp)->SE_init((CryptoCoreContainer *)pctx->imp, mode, padding, hwkey_unique,key_len,hwiv_unique);
+               }
+       }
+       else
+       {
+               ret = ((CryptoCoreContainer *)pctx->imp)->SE_init((CryptoCoreContainer *)pctx->imp, mode, padding, key,key_len, iv);
+
+       }
+
+       if(ret == CRYPTO_INVALID_ARGUMENT)
+       {
+               return UCI_INVALID_ARGUMENT;
+       }
+       if(ret != CRYPTO_SUCCESS)
+       {
+               return UCI_ERROR;
+       }
+
+       return UCI_SUCCESS;
 #endif
 }
 
 int hwcrypto_se_process(UCI_HANDLE oh, unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len)
 {
 #ifndef PC_I586
-    uci_context_s       *pctx = NULL;
-    unsigned int         alg  = 0;
-    unsigned int         counter = 0;
-    struct crypt_oper   oper;
-    int                  ret  = 0;
-    int                  blocksize = 0;
-
-    memset(&oper, 0, sizeof(struct crypt_oper));
-
-    pctx = (uci_context_s*)oh;
-    if(pctx == NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    if(pctx->handle < 0)
-    {
-        TA_PRINT("Handle error \n");
-        return UCI_ERROR;
-    }
-    if(output_len != NULL)
-    {
-        *output_len = 0;
-    }
-
-    if(alg == ID_UCI_AES128 || alg == ID_UCI_AES256)
-    {
-        if((input_len % 16) != 0)
-        {
-            TA_PRINT("input_len error\n");
-            return UCI_ERROR;
-        }
-        blocksize = 16;
-    }
-    if(alg == ID_UCI_DES || alg == ID_UCI_TDES)
-    {
-        if((input_len % 8) != 0)
-        {
-            TA_PRINT("input_len error\n");
-            return UCI_ERROR;
-        }
-        blocksize = 8;
-    }
-
-    oper.src_addr = input;
-    oper.src_len  = input_len;
-    oper.dst_addr = output;
-    oper.dst_len  = output_len;
-    if (ret = ioctl(pctx->handle, IOCTL_CRYPTO_CRYPT, &oper))
-    {
-        TA_PRINT("error:ioctl(pctx->handle , 1, &oper) returned %d\n",ret);
-        return UCI_ERROR;
-    }
-
-    return UCI_SUCCESS;
+       uci_context_s       *pctx = NULL;
+       unsigned int         alg  = 0;
+       unsigned int         counter = 0;
+       struct crypt_oper   oper;
+       int                  ret  = 0;
+       int                  blocksize = 0;
+
+       memset(&oper, 0, sizeof(struct crypt_oper));
+
+       pctx = (uci_context_s*)oh;
+       if(pctx == NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       if(pctx->handle < 0)
+       {
+               TA_PRINT("Handle error \n");
+               return UCI_ERROR;
+       }
+       if(output_len != NULL)
+       {
+               *output_len = 0;
+       }
+
+       if(alg == ID_UCI_AES128 || alg == ID_UCI_AES256)
+       {
+               if((input_len % 16) != 0)
+               {
+                       TA_PRINT("input_len error\n");
+                       return UCI_ERROR;
+               }
+               blocksize = 16;
+       }
+       if(alg == ID_UCI_DES || alg == ID_UCI_TDES)
+       {
+               if((input_len % 8) != 0)
+               {
+                       TA_PRINT("input_len error\n");
+                       return UCI_ERROR;
+               }
+               blocksize = 8;
+       }
+
+       oper.src_addr = input;
+       oper.src_len  = input_len;
+       oper.dst_addr = output;
+       oper.dst_len  = output_len;
+       if (ret = ioctl(pctx->handle, IOCTL_CRYPTO_CRYPT, &oper))
+       {
+               TA_PRINT("error:ioctl(pctx->handle , 1, &oper) returned %d\n",ret);
+               return UCI_ERROR;
+       }
+
+       return UCI_SUCCESS;
 #else
-    int ret;
-    uci_context_s *ucictx = (uci_context_s *)oh;
-    if(ucictx == NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    ret = ((CryptoCoreContainer *)ucictx->imp)->SE_process((CryptoCoreContainer*)(ucictx->imp), input, input_len, output, output_len);
-    if(ret != CRYPTO_SUCCESS)
-    {
-        return UCI_ERROR;
-    }
-    return UCI_SUCCESS;
+       int ret;
+       uci_context_s *ucictx = (uci_context_s *)oh;
+       if(ucictx == NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       ret = ((CryptoCoreContainer *)ucictx->imp)->SE_process((CryptoCoreContainer*)(ucictx->imp), input, input_len, output, output_len);
+       if(ret != CRYPTO_SUCCESS)
+       {
+               return UCI_ERROR;
+       }
+       return UCI_SUCCESS;
 
 #endif
 }
@@ -645,168 +651,168 @@ int hwcrypto_se_process(UCI_HANDLE oh, unsigned char *input, unsigned int input_
 int hwcrypto_se_final(UCI_HANDLE  oh, unsigned char *input, unsigned int input_len, unsigned char *output, unsigned int *output_len)
 {
 #ifndef PC_I586
-    uci_context_s       *pctx = NULL;
-    struct crypt_oper   oper;
-    struct crypt_info   *info = NULL;
-    int                  ret  = -1;
-    int                  hndl = -1;
-    unsigned int         blocksize = 0;
-    unsigned int         alg       = 0;
-    unsigned int         padlen    = 0;
-    unsigned int         len       = 0;
-    unsigned int         lastlen   = 0;
-    unsigned char        padding[32] = {0x0};
-
-    memset(padding, 0, sizeof(padding)/sizeof(padding[0]));
-    memset(&oper, 0, sizeof(struct crypt_oper));
-    pctx = (uci_context_s*)oh;
-    if(pctx == NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-
-    info = (struct crypt_info*) pctx->imp;
-    if(info == NULL)
-    {
-      return UCI_INVALID_HANDLE;
-    }
-    hndl = pctx->handle;
-    alg  = pctx->alg;
-    if(hndl < 0)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    if(alg == ID_UCI_AES128 || alg == ID_UCI_AES256)
-    {
-        blocksize = 16;
-    }
-    else if(alg == ID_UCI_DES|| alg == ID_UCI_TDES)
-    {
-        blocksize = 8;
-    }
-    else
-    {
-        return
+       uci_context_s       *pctx = NULL;
+       struct crypt_oper   oper;
+       struct crypt_info   *info = NULL;
+       int                  ret  = -1;
+       int                  hndl = -1;
+       unsigned int         blocksize = 0;
+       unsigned int         alg       = 0;
+       unsigned int         padlen    = 0;
+       unsigned int         len       = 0;
+       unsigned int         lastlen   = 0;
+       unsigned char        padding[32] = {0x0};
+
+       memset(padding, 0, sizeof(padding)/sizeof(padding[0]));
+       memset(&oper, 0, sizeof(struct crypt_oper));
+       pctx = (uci_context_s*)oh;
+       if(pctx == NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+
+       info = (struct crypt_info*) pctx->imp;
+       if(info == NULL)
+       {
+         return UCI_INVALID_HANDLE;
+       }
+       hndl = pctx->handle;
+       alg  = pctx->alg;
+       if(hndl < 0)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       if(alg == ID_UCI_AES128 || alg == ID_UCI_AES256)
+       {
+               blocksize = 16;
+       }
+       else if(alg == ID_UCI_DES|| alg == ID_UCI_TDES)
+       {
+               blocksize = 8;
+       }
+       else
+       {
+               return
 UCI_INVALID_HANDLE;
-    }
-
-    if(pctx->mode == ID_UCI_ENC_CBC || pctx->mode == ID_UCI_ENC_CTR || pctx->mode == ID_UCI_ENC_ECB)/*encrypt*/
-    {
-        lastlen = input_len % blocksize;
-        if(input_len > lastlen ) /* last blocksize is bigger than blocksize or equal to blocksize*/
-        {
-            len = input_len -lastlen;
-            ret = hwcrypto_se_process(oh,input,len,output,output_len);
-            if(ret != UCI_SUCCESS)
-            {
-                TA_PRINT("hwcrypto_se_process error \n");
-                return ret;
-            }
-        }
-        if(MI_GET_PADDING(info->mode) == _PAD_PKCS7_)/*do padding*/
-        {
-
-            if(lastlen >0)
-            {
-                memcpy(padding, input + len, lastlen);
-            }
-            memset(padding + lastlen, blocksize - lastlen, blocksize - lastlen);
-            oper.src_addr = padding;
-            oper.src_len  = blocksize;
-            oper.dst_addr = output + len;
-            oper.dst_len  = output_len;
+       }
+
+       if(pctx->mode == ID_UCI_ENC_CBC || pctx->mode == ID_UCI_ENC_CTR || pctx->mode == ID_UCI_ENC_ECB)/*encrypt*/
+       {
+               lastlen = input_len % blocksize;
+               if(input_len > lastlen ) /* last blocksize is bigger than blocksize or equal to blocksize*/
+               {
+                       len = input_len -lastlen;
+                       ret = hwcrypto_se_process(oh,input,len,output,output_len);
+                       if(ret != UCI_SUCCESS)
+                       {
+                               TA_PRINT("hwcrypto_se_process error \n");
+                               return ret;
+                       }
+               }
+               if(MI_GET_PADDING(info->mode) == _PAD_PKCS7_)/*do padding*/
+               {
+
+                       if(lastlen >0)
+                       {
+                               memcpy(padding, input + len, lastlen);
+                       }
+                       memset(padding + lastlen, blocksize - lastlen, blocksize - lastlen);
+                       oper.src_addr = padding;
+                       oper.src_len  = blocksize;
+                       oper.dst_addr = output + len;
+                       oper.dst_len  = output_len;
                        //oper.final   = 1;
 
-            if(ret = ioctl(hndl, IOCTL_CRYPTO_CRYPT, &oper))
-            {
-                TA_PRINT("error:ioctl(hndl, 1, &oper) returned %d\n",ret);
-                return UCI_ERROR;
-            }
-
-            *output_len = input_len - lastlen + blocksize;
-        }
-        if(MI_GET_PADDING(info->mode) == _PAD_NO_)/*do padding*/
-        {
-            if(lastlen >0)
-            {
-                memcpy(output + len, output + len, lastlen);
-            }
-            *output_len = input_len ;
-        }
-    }
-    else/*decrypt*/
-    {
-        lastlen = input_len % blocksize;
-        if(input_len > lastlen)
-        {
-            len = input_len -lastlen;
-        }
-        if(len > 0)
-        {
-
-            oper.src_addr = (char *)input;
-            oper.src_len      = len;
-            oper.dst_addr = (char *)output;
-            oper.dst_len  = output_len;
+                       if(ret = ioctl(hndl, IOCTL_CRYPTO_CRYPT, &oper))
+                       {
+                               TA_PRINT("error:ioctl(hndl, 1, &oper) returned %d\n",ret);
+                               return UCI_ERROR;
+                       }
+
+                       *output_len = input_len - lastlen + blocksize;
+               }
+               if(MI_GET_PADDING(info->mode) == _PAD_NO_)/*do padding*/
+               {
+                       if(lastlen >0)
+                       {
+                               memcpy(output + len, output + len, lastlen);
+                       }
+                       *output_len = input_len ;
+               }
+       }
+       else/*decrypt*/
+       {
+               lastlen = input_len % blocksize;
+               if(input_len > lastlen)
+               {
+                       len = input_len -lastlen;
+               }
+               if(len > 0)
+               {
+
+                       oper.src_addr = (char *)input;
+                       oper.src_len      = len;
+                       oper.dst_addr = (char *)output;
+                       oper.dst_len  = output_len;
                        //oper.final    = 1;
-            if (ret = ioctl(hndl, IOCTL_CRYPTO_CRYPT, &oper))
-            {
-                TA_PRINT("error:ioctl(hndl, 1, &oper) returned %d\n",ret);
-                return UCI_ERROR;
-            }
-        }
-        if(MI_GET_PADDING(info->mode) == _PAD_NO_)/*do padding*/
-        {
-            if(lastlen >0)
-            {
-                memcpy(output + len, input + len, lastlen);
-            }
-            *output_len = input_len ;
-        }
-        if(MI_GET_PADDING(info->mode) == _PAD_PKCS7_)/*de padding*/
-        {
-            if(lastlen >0)
-            {
-                TA_PRINT("psrc_len is not aligen to %d\n",blocksize);
-                return UCI_ERROR;
-            }
-
-            padlen = output[input_len -1];
-            //PrintBYTE("padding",output,input_len);
-            //PrintBYTE("input",input,input_len);
-            if(padlen < 1 || padlen > 16)
-            {
-                *output_len = 0;
-                TA_PRINT("padding size{%d} is incorretc ",padlen);
-                return UCI_ERROR;
-            }
-            memset(padding, padlen, blocksize);
-            if(memcmp(output + input_len - padlen ,padding, padlen) != 0)
-            {
-                *output_len = 0;
-                TA_PRINT("padding size{%d} is incorretc ",padlen);
-                return UCI_ERROR;
-            }
-
-            *output_len = input_len - padlen;
-        }
-
-    }
-
-    return UCI_SUCCESS;
+                       if (ret = ioctl(hndl, IOCTL_CRYPTO_CRYPT, &oper))
+                       {
+                               TA_PRINT("error:ioctl(hndl, 1, &oper) returned %d\n",ret);
+                               return UCI_ERROR;
+                       }
+               }
+               if(MI_GET_PADDING(info->mode) == _PAD_NO_)/*do padding*/
+               {
+                       if(lastlen >0)
+                       {
+                               memcpy(output + len, input + len, lastlen);
+                       }
+                       *output_len = input_len ;
+               }
+               if(MI_GET_PADDING(info->mode) == _PAD_PKCS7_)/*de padding*/
+               {
+                       if(lastlen >0)
+                       {
+                               TA_PRINT("psrc_len is not aligen to %d\n",blocksize);
+                               return UCI_ERROR;
+                       }
+
+                       padlen = output[input_len -1];
+                       //PrintBYTE("padding",output,input_len);
+                       //PrintBYTE("input",input,input_len);
+                       if(padlen < 1 || padlen > 16)
+                       {
+                               *output_len = 0;
+                               TA_PRINT("padding size{%d} is incorretc ",padlen);
+                               return UCI_ERROR;
+                       }
+                       memset(padding, padlen, blocksize);
+                       if(memcmp(output + input_len - padlen ,padding, padlen) != 0)
+                       {
+                               *output_len = 0;
+                               TA_PRINT("padding size{%d} is incorretc ",padlen);
+                               return UCI_ERROR;
+                       }
+
+                       *output_len = input_len - padlen;
+               }
+
+       }
+
+       return UCI_SUCCESS;
 #else
-    int ret;
-    uci_context_s *ucictx = (uci_context_s *)oh;
-    if(ucictx==NULL)
-    {
-        return UCI_INVALID_HANDLE;
-    }
-    ret = ((CryptoCoreContainer *)ucictx->imp)->SE_final((CryptoCoreContainer*)(ucictx->imp), input, input_len, output, output_len);
-    if(ret!=CRYPTO_SUCCESS)
-    {
-        return UCI_ERROR;
-    }
-    return UCI_SUCCESS;
+       int ret;
+       uci_context_s *ucictx = (uci_context_s *)oh;
+       if(ucictx==NULL)
+       {
+               return UCI_INVALID_HANDLE;
+       }
+       ret = ((CryptoCoreContainer *)ucictx->imp)->SE_final((CryptoCoreContainer*)(ucictx->imp), input, input_len, output, output_len);
+       if(ret!=CRYPTO_SUCCESS)
+       {
+               return UCI_ERROR;
+       }
+       return UCI_SUCCESS;
 
 #endif
 }
index 83e0ef0..54f8582 100644 (file)
@@ -51,7 +51,7 @@ typedef struct
        TEE_OperationInfo info;
        TEE_ObjectHandle key1;
        TEE_ObjectHandle key2;
-       int crypto; // handle to crypto driver or ponter to crypto library context
+       void* crypto; // handle to crypto driver or ponter to crypto library context
        unsigned char data[MAX_BLOCK_SIZE];  // accumulated stream data
        unsigned int data_len;  // accumulated data length
        unsigned int block_len; // cipher block data length
index c2af260..4a2eb36 100644 (file)
@@ -899,9 +899,9 @@ static int sw_crypto_open(crypto_internal_operation *operation)
                        break;
        }
 
-       operation->crypto=(int)create_CryptoCoreContainer(alg);
+       operation->crypto = (void*)create_CryptoCoreContainer(alg);
 
-       if(operation->crypto==0) {
+       if(operation->crypto == NULL) {
                goto error;
        }
        return 0;
@@ -916,7 +916,7 @@ static int sw_crypto_close(crypto_internal_operation *operation)
        if(operation->crypto) {
                destroy_CryptoCoreContainer((CryptoCoreContainer*)operation->crypto);
        }
-       operation->crypto = -1;
+       operation->crypto = NULL;
        return rc;
 }
 
@@ -1013,7 +1013,7 @@ int crypto_internal_update(crypto_internal_operation *operation, unsigned char *
                        size_t should_be_processed_of_bytes = (size_t)in_size/operation->block_len*operation->block_len;
                        size_t remaining_number_of_bytes = in_size-should_be_processed_of_bytes;
 
-                       CRYPTO_INTERNAL_LOG("should_be_processed_of_bytes=%d remaining_number_of_bytes=%d processed=%d", should_be_processed_of_bytes, remaining_number_of_bytes, total_processing_len);
+                       CRYPTO_INTERNAL_LOG("should_be_processed_of_bytes=%zd remaining_number_of_bytes=%zd processed=%d", should_be_processed_of_bytes, remaining_number_of_bytes, total_processing_len);
                        if (should_be_processed_of_bytes != 0)
                        {
                                processing_len = out_size-total_processing_len;
@@ -1069,7 +1069,7 @@ int crypto_internal_update(crypto_internal_operation *operation, unsigned char *
                        size_t should_be_processed_of_bytes = (size_t)in_size/operation->block_len*operation->block_len;
                        size_t remaining_number_of_bytes = in_size-should_be_processed_of_bytes;
 
-                       CRYPTO_INTERNAL_LOG("should_be_processed_of_bytes=%d remaining_number_of_bytes=%d processed=%d", should_be_processed_of_bytes, remaining_number_of_bytes, total_processing_len);
+                       CRYPTO_INTERNAL_LOG("should_be_processed_of_bytes=%zd remaining_number_of_bytes=%zd processed=%d", should_be_processed_of_bytes, remaining_number_of_bytes, total_processing_len);
                        if (should_be_processed_of_bytes != 0)
                        {
                                if (crypto_update_engine(operation, in_data, should_be_processed_of_bytes, NULL, NULL)) {
@@ -1182,7 +1182,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s
                        size_t should_be_processed_of_bytes = (size_t)in_size/operation->block_len*operation->block_len;
                        size_t remaining_number_of_bytes = in_size-should_be_processed_of_bytes;
 
-                       CRYPTO_INTERNAL_LOG("should_be_processed_of_bytes=%d remaining_number_of_bytes=%d processed=%d", should_be_processed_of_bytes, remaining_number_of_bytes, total_processing_len);
+                       CRYPTO_INTERNAL_LOG("should_be_processed_of_bytes=%zd remaining_number_of_bytes=%zd processed=%d", should_be_processed_of_bytes, remaining_number_of_bytes, total_processing_len);
                        if (should_be_processed_of_bytes != 0)
                        {
                                processing_len = out_size-total_processing_len;
@@ -1205,7 +1205,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s
                                        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=%d !!", remaining_number_of_bytes);
+                                       CRYPTO_INTERNAL_LOG("ENC NOPAD : Ignore remaining_number_of_bytes=%zd !!", remaining_number_of_bytes);
                                        goto exit;
                                }
 
@@ -1273,7 +1273,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s
                                        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=%d !!", remaining_number_of_bytes);
+                                       CRYPTO_INTERNAL_LOG("DEC NOPAD : Ignore remaining_number_of_bytes=%zd !!", remaining_number_of_bytes);
                                        goto exit;
                                }
                                /* PAD */
@@ -1306,7 +1306,7 @@ int crypto_internal_final(crypto_internal_operation *operation, unsigned char *s
                                }
                                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=%d !!", remaining_number_of_bytes);
+                                       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)
@@ -2041,7 +2041,7 @@ void TEE_CopyOperation( TEE_OperationHandle dstOperation, TEE_OperationHandle sr
                }
        }
        else {
-               dstOp->crypto = -1;
+               dstOp->crypto = NULL;
        }
        return;
 }
index e60e684..59988f0 100644 (file)
@@ -42,7 +42,7 @@ int ossl_crypto_open(crypto_internal_operation *op)
                return -1;
        }
 
-       op->crypto = (int)ctx;
+       op->crypto = (void*)ctx;
        return 0;
 }
 
index 62ab538..0bfc99f 100644 (file)
@@ -1243,22 +1243,28 @@ void convert_TA_UUID(char* uuid, TEE_UUID TA_UUID) {
 }
 
 int gen_random(uint8_t* dest, uint8_t data_len) {
-       UCI_HANDLE uh = UCI_ERROR;
-       uh = uci_context_alloc(ID_UCI_X931, UCI_SW_CRYPTOCORE);
-       if (uh == UCI_ERROR || uh == UCI_MEM_ALLOR_ERROR) {
+       UCI_HANDLE uh = NULL;
+       int ret = UCI_SUCCESS;
+
+       ret = uci_context_alloc(ID_UCI_X931, UCI_SW_CRYPTOCORE, &uh);
+       if (ret == UCI_ERROR || ret == UCI_MEM_ALLOR_ERROR) {
                return -1;
        }
+
        unsigned char seed[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08,
            0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};
-       int ret = uci_prng_seed(uh, seed);
+       ret = uci_prng_seed(uh, seed);
        if (ret != UCI_SUCCESS) {
                goto out;
        }
+
        ret = uci_prng_get(uh, data_len * 8, dest);
        if (ret != UCI_SUCCESS) {
                goto out;
        }
-       out: uci_context_free(uh);
+
+out:
+       uci_context_free(uh);
        return ret;
 }
 
@@ -1723,7 +1729,12 @@ TEE_Result TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
                        } else if (4096 == keySize) {
                                alg = ID_UCI_RSA4096;
                        }
-                       UCI_HANDLE uh = uci_context_alloc(alg, UCI_SW);
+                       UCI_HANDLE uh = NULL;
+                       int ret = uci_context_alloc(alg, UCI_SW, &uh);
+                       if (ret != UCI_SUCCESS) {
+                               TZ_ERROR("Context creation failed: %d line: %d,%s", ret, __LINE__, __func__);
+                               TEE_Panic(0);
+                       }
                        uci_ae_gen_keypair(uh, &uci_key, &up);
                        uci_context_free(uh);
 
@@ -1772,7 +1783,12 @@ TEE_Result TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
                                TEE_Panic(0);
                        }
                        // generate public & private keys. algorithm is the same as for DH
-                       UCI_HANDLE handle = uci_context_alloc(ID_UCI_DSA, UCI_SW);
+                       UCI_HANDLE handle = NULL;
+                       int ret = uci_context_alloc(ID_UCI_DSA, UCI_SW, &handle);
+                       if (ret != UCI_SUCCESS) {
+                               TZ_ERROR("Context creation failed: %d line: %d,%s", ret, __LINE__, __func__);
+                               TEE_Panic(0);
+                       }
                        uci_ae_gen_keypair(handle, &uci_key, &up);
                        uci_context_free(handle);
                        for (i = 0; i < paramCount; i++) {
@@ -1810,7 +1826,12 @@ TEE_Result TEE_GenerateKey(TEE_ObjectHandle object, uint32_t keySize,
                                TZ_ERROR("operation error line = %d,%s\n", __LINE__, __func__);
                                TEE_Panic(0);
                        }
-                       UCI_HANDLE handle = uci_context_alloc(ID_UCI_DH, UCI_SW);
+                       UCI_HANDLE handle = NULL;
+                       int ret = uci_context_alloc(ID_UCI_DH, UCI_SW, &handle);
+                       if (ret != UCI_SUCCESS) {
+                               TZ_ERROR("Context creation failed: %d line: %d,%s", ret, __LINE__, __func__);
+                               TEE_Panic(0);
+                       }
                        uci_dh_gen_phasekey(handle, privKey, pubKey, &uciparam);
                        uci_context_free(handle);
                        for (i = 0; i < paramCount; i++) {