# 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
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
virtual ~Property() {\r
}\r
;\r
- unsigned int propset;\r
+ uintptr_t propset;\r
};\r
\r
#endif /* PROPERTYACCESS_PROPERTY_H_ */\r
* @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
\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
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
if(!_allowPropertyAccess)\r
{\r
break;\r
- } \r
+ }\r
newEnumHandle->property = new ClientProperty(pv);\r
break;\r
}\r
}\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
} 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
\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
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
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;
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) {
//#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
#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;
memcpy((void*)sem->bName, (const void*)pcName, (size_t)10);
sem->bName[10] = '\0';
- *puiSmid = (unsigned int)sem;
+ *puiSmid = (void*)sem;
return iRetVal;
}
}
#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;
}
}
-static int UlOsaNamedSemRelease(unsigned int uiSmid) {
+static int UlOsaNamedSemRelease(void *uiSmid) {
UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
struct sembuf semBuf;
}
}
-static int UlOsaNamedSemReset(unsigned int uiSmid) {
+static int UlOsaNamedSemReset(void *uiSmid) {
UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
union semun semUnion;
return OSAL_OK;
}
-static int UlOsaNamedSemGetval(unsigned int uiSmid) {
+static int UlOsaNamedSemGetval(void *uiSmid) {
UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
int n;
}
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);
}
/* 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));
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) {
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;
}
}
-static int UlOsaSemRelease(unsigned int uiSmid) {
+static int UlOsaSemRelease(void *uiSmid) {
UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
if (!sem) {
return OSAL_ERROR;
}
}
-static int UlOsaSemReset(unsigned int uiSmid) {
+static int UlOsaSemReset(void *uiSmid) {
UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
if (!sem) {
return OSAL_ERROR;
return OSAL_OK;
}
-static int UlOsaSemGetval(unsigned int uiSmid) {
+static int UlOsaSemGetval(void *uiSmid) {
UlOsaSem_t *sem = (UlOsaSem_t*)uiSmid;
int n;
if (!sem) {
/**
* @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);
}
* @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.
- 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);
}
* @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);
}
* @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);
}
* @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);
}
* @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);
}
/*
// $$$
//-----------------------------------------------------------------------------
- // 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;
break;
}
- (*puiMutid) = (unsigned int)pmutex_t;
+ (*puiMutid) = (void*)pmutex_t;
pthread_mutexattr_destroy(&attr_t);
} else {
/*
// $$$
//-----------------------------------------------------------------------------
- // 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
//------------------------------------------------------------------------------
// $$$
*/
-int OsaMutDelete(unsigned int uiMutid) {
+int OsaMutDelete(void *uiMutid) {
int iRet;
pthread_mutex_t* pmutex_t = (pthread_mutex_t *)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;
/*
// $$$
//-----------------------------------------------------------------------------
- // Function Name : OsaMutGet
- // Detail Description : This function locks the mutex.
+ // Function Name : OsaMutGet
+ // Detail Description : This function locks the mutex.
//
// Return Data Type : ErrorType
//
//------------------------------------------------------------------------------
// $$$
*/
-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);
// 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;
//------------------------------------------------------------------------------
// $$$
*/
-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) {
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);
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);
}
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);
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);
param_t.__sched_priority = iPriority;
iRet = pthread_setschedparam(createThread, createThreadPolicy, ¶m_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;
/*
// $$$
//-----------------------------------------------------------------------------
- // Function Name : OsaExit
+ // Function Name : OsaExit
// Detail Description : This function terminates the calling thread.
//
// Return Data Type : Void
//
- // Programming Note : None.
+ // Programming Note : None.
//------------------------------------------------------------------------------
// $$$
*/
/*
// $$$
//-----------------------------------------------------------------------------
- // 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
//
//------------------------------------------------------------------------------
// $$$
*/
-int OsaTaskDelete(unsigned int uiTid) {
+int OsaTaskDelete(void *uiTid) {
int iRet = 0;
iRet = pthread_cancel((pthread_t)uiTid);
if (iRet) {
/*
// $$$
//-----------------------------------------------------------------------------
- // 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.
//------------------------------------------------------------------------------
// $$$
*/
/*
// $$$
//-----------------------------------------------------------------------------
- // 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
//
/*
// $$$
//-----------------------------------------------------------------------------
- // Function Name : OsaTaskNanosleep
+ // Function Name : OsaTaskNanosleep
// Detail Description : This function makes the thread to sleep for nanosec
- // precision.
+ // precision.
//
// Return Data Type : ErrorType
//
/*
// $$$
//-----------------------------------------------------------------------------
- // 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 .
//
/*
// $$$
//-----------------------------------------------------------------------------
- // Function Name : OsaTaskDelaymsecs
+ // Function Name : OsaTaskDelaymsecs
// Detail Description : This function makes the thread to sleep for millisec
- // precision.
+ // precision.
//
// Return Data Type : ErrorType
//
#include <signal.h>
#include <sys/ipc.h>
-#include <mqueue.h>
+#include <mqueue.h>
#endif
#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
#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)
#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
#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
}
#else
#define OSAL_ASSERT(expression) assert(expression)
-#endif
+#endif
/*-----------------------------------------------------------------------------
* Globals
/*-----------------------------------------------------------------------------
* 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(void* pvArg);
+void OsaExitKthread(void *pvArg);
/* setup thread environment (called by new thread) */
-void OsaInitKthread(void* pvArg);
+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.
* @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.
- 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
* @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.
* @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
* @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.
* @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,
//------------------------------------------------------------------------------
// $$$
*/
-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
}
* 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
} 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
// 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;
}
/**
* @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.
* @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
* @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
*/
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);
* 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.
*/
* @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.
*/
* @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.
*/
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
* 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.
*/
#ifdef __cplusplus
}
-#endif
+#endif
#endif
* @brief UCI handle.
*
*/
-typedef int UCI_HANDLE;
+typedef void* UCI_HANDLE;
/**
* @brief UCI return error type.
*
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;
}
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;
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;
}
#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);
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) {
*/
#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
}
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
}
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
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;
if(operation->crypto) {
destroy_CryptoCoreContainer((CryptoCoreContainer*)operation->crypto);
}
- operation->crypto = -1;
+ operation->crypto = NULL;
return rc;
}
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;
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)) {
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;
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;
}
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 */
}
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)
}
}
else {
- dstOp->crypto = -1;
+ dstOp->crypto = NULL;
}
return;
}
return -1;
}
- op->crypto = (int)ctx;
+ op->crypto = (void*)ctx;
return 0;
}
}
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;
}
} 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);
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++) {
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++) {