summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsangwan.kwon <sangwan.kwon@samsung.com>2017-04-27 16:23:59 +0900
committersangwan.kwon <sangwan.kwon@samsung.com>2017-04-27 16:23:59 +0900
commit1708350cf7b62d346fa3b12b10bab5e11cb41d7d (patch)
tree942c696c8d483292503ea63f7610c9c9c65748c9
parent3d77d11982b580994c47c9be5b47b8f44efce5df (diff)
downloadlibcryptsvc-1708350cf7b62d346fa3b12b10bab5e11cb41d7d.tar.gz
libcryptsvc-1708350cf7b62d346fa3b12b10bab5e11cb41d7d.tar.bz2
libcryptsvc-1708350cf7b62d346fa3b12b10bab5e11cb41d7d.zip
Adjust tizen coding rule
Change-Id: Ie05c2149eea334829d6bdf9b0951ae301b4abbd0 Signed-off-by: sangwan.kwon <sangwan.kwon@samsung.com>
-rw-r--r--gadget/duid-gadget.c18
-rw-r--r--include/SecCryptoSvc.h88
-rw-r--r--include/SecTzSvc.h10
-rw-r--r--include/device_info.h4
-rw-r--r--srcs/SecCryptoSvc.c62
-rw-r--r--srcs/device_info.c10
-rw-r--r--test/colour_log_formatter.h84
7 files changed, 134 insertions, 142 deletions
diff --git a/gadget/duid-gadget.c b/gadget/duid-gadget.c
index 799b926..31aa676 100644
--- a/gadget/duid-gadget.c
+++ b/gadget/duid-gadget.c
@@ -22,16 +22,14 @@
int main()
{
- char *duid = GetDuid(20);
+ char *duid = GetDuid(20);
- if (duid == NULL) {
- fprintf(stderr, "Failed to get duid\n");
- return 0;
- }
+ if (duid == NULL) {
+ fprintf(stderr, "Failed to get duid\n");
+ return 0;
+ }
- printf("%s", duid);
-
- free(duid);
-
- return 1;
+ printf("%s", duid);
+ free(duid);
+ return 1;
}
diff --git a/include/SecCryptoSvc.h b/include/SecCryptoSvc.h
index 6a9f696..4d5e572 100644
--- a/include/SecCryptoSvc.h
+++ b/include/SecCryptoSvc.h
@@ -33,27 +33,27 @@ extern "C"
/*typedef enum
{
- SEC_CRYPTO_CIPHER_NULL = 0,
- SEC_CRYPTO_CIPHER_AES_CBC_128,
- SEC_CRYPTO_CIPHER_SEED_CBC,
- SEC_CRYPTO_CIPHER_AES_CBC_192,
- SEC_CRYPTO_CIPHER_AES_CBC_256,
- SEC_CRYPTO_CIPHER_AES_CTR_128,
- SEC_CRYPTO_CIPHER_AES_ECB_128,
- SEC_CRYPTO_CIPHER_AES_ECB_192,
- SEC_CRYPTO_CIPHER_AES_ECB_256
+ SEC_CRYPTO_CIPHER_NULL = 0,
+ SEC_CRYPTO_CIPHER_AES_CBC_128,
+ SEC_CRYPTO_CIPHER_SEED_CBC,
+ SEC_CRYPTO_CIPHER_AES_CBC_192,
+ SEC_CRYPTO_CIPHER_AES_CBC_256,
+ SEC_CRYPTO_CIPHER_AES_CTR_128,
+ SEC_CRYPTO_CIPHER_AES_ECB_128,
+ SEC_CRYPTO_CIPHER_AES_ECB_192,
+ SEC_CRYPTO_CIPHER_AES_ECB_256
} SecCryptoCipherAlg;
typedef enum
{
- SEC_SUCCESS = 0,
- SEC_CRYPTO_ERROR_1, //algorithm error
- SEC_CRYPTO_ERROR_2, //init error
- SEC_CRYPTO_ERROR_3, //update error
- SEC_CRYPTO_ERROR_4, //final error
- SEC_CRYPTO_ERROR_5, //wrong param
- SEC_CRYPTO_ERROR_6, //Memory alloc
- SEC_CRYPTO_ERROR_7, //Internal error
+ SEC_SUCCESS = 0,
+ SEC_CRYPTO_ERROR_1, //algorithm error
+ SEC_CRYPTO_ERROR_2, //init error
+ SEC_CRYPTO_ERROR_3, //update error
+ SEC_CRYPTO_ERROR_4, //final error
+ SEC_CRYPTO_ERROR_5, //wrong param
+ SEC_CRYPTO_ERROR_6, //Memory alloc
+ SEC_CRYPTO_ERROR_7, //Internal error
} SecError;
*/
@@ -80,18 +80,18 @@ typedef enum
#define UINT32 unsigned int
#endif
-//#define EVP_ERROR 0
-//#define SEC_CRYPTO_ENCRYPT 1
-//#define SEC_CRYPTO_DECRYPT 0
-#define SEC_DUK_SIZE 16
-//#define SEC_CRYPTO_KEY_LENGTH 16
-//#define SEC_CRYPTP_ARR_LENGTH 1024
-#define SEC_FRAME_OSP_KEY "uniqueKey"
-//#define SHA1_DIGEST_VALUE_LEN 20
-#define SHA256_DIGEST_VALUE_LEN 32
-//#define KDF_KEYLEN 16
-#define HASH_LEN 20
-//#define SEC_KEYMGR_FEK_SIZE 16
+//#define EVP_ERROR 0
+//#define SEC_CRYPTO_ENCRYPT 1
+//#define SEC_CRYPTO_DECRYPT 0
+#define SEC_DUK_SIZE 16
+//#define SEC_CRYPTO_KEY_LENGTH 16
+//#define SEC_CRYPTP_ARR_LENGTH 1024
+#define SEC_FRAME_OSP_KEY "uniqueKey"
+//#define SHA1_DIGEST_VALUE_LEN 20
+#define SHA256_DIGEST_VALUE_LEN 32
+//#define KDF_KEYLEN 16
+#define HASH_LEN 20
+//#define SEC_KEYMGR_FEK_SIZE 16
#define CS_ERROR_NONE 0
#define CS_ERROR_BAD_ALLOC -1
@@ -100,27 +100,27 @@ typedef enum
/*------ Base64 Encoding Table ------*/
static const char Base64EncodingTable[] = {
- 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
- 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
- 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
- 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
- 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
- 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
- 'w', 'x', 'y', 'z', '0', '1', '2', '3',
+ 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
+ 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
+ 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
+ 'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
+ 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
+ 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
+ 'w', 'x', 'y', 'z', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', '+', '/'
};
/**
- * This function provides Device UniqueKey for crypto with Hash
- * @return This function returns TRUE on success
- * @param[in] uLen Length of Device UniqueKey
- * @param[in,out] pCek Device UniqueKey(Hashed)
+ * This function provides Device UniqueKey for crypto with Hash
+ * @return This function returns TRUE on success
+ * @param[in] uLen Length of Device UniqueKey
+ * @param[in,out] pCek Device UniqueKey(Hashed)
*/
bool SecFrameGeneratePlatformUniqueKey(IN UINT32 uLen, IN OUT UINT8 *pCek);
-char* Base64Encoding(const char *data, int size);
+char *Base64Encoding(const char *data, int size);
-char* GetDuid(int size);
+char *GetDuid(int size);
/*
* Password based derivation routines with platform key
@@ -140,11 +140,11 @@ char* GetDuid(int size);
* and keylen should be bigger than 0
*/
int cs_derive_key_with_pass(const char *pass, int passlen, int keylen,
- unsigned char **key);
+ unsigned char **key);
#ifdef __cplusplus
}
#endif
-#endif // _SEC_CRYPTO_SVC_H
+#endif // _SEC_CRYPTO_SVC_H
diff --git a/include/SecTzSvc.h b/include/SecTzSvc.h
index 5ac5886..c4485e3 100644
--- a/include/SecTzSvc.h
+++ b/include/SecTzSvc.h
@@ -58,7 +58,10 @@ typedef unsigned long TZCRYPT_UINT64;
* return SEC_CRYPTO_SUCCESS if operation has been succesfully completed. (Refer to the tlc error code)
*/
__attribute__((visibility("default")))
-TZCRYPT_Result SecEncryptTZCrypt(TZCRYPT_UINT8 *Src, TZCRYPT_UINT32 SrcLen, TZCRYPT_UINT8 *Dst, TZCRYPT_UINT32 *DstLen, TZCRYPT_UINT8 *AppInfo, TZCRYPT_UINT32 AppInfoLen, TZCRYPT_UINT8 *WrapAppInfo, TZCRYPT_UINT32 *WrapAppInfoLen);
+TZCRYPT_Result SecEncryptTZCrypt(TZCRYPT_UINT8 *Src, TZCRYPT_UINT32 SrcLen,
+ TZCRYPT_UINT8 *Dst, TZCRYPT_UINT32 *DstLen, TZCRYPT_UINT8 *AppInfo,
+ TZCRYPT_UINT32 AppInfoLen, TZCRYPT_UINT8 *WrapAppInfo,
+ TZCRYPT_UINT32 *WrapAppInfoLen);
/*
* This function provides an decryption of user data.
@@ -76,7 +79,10 @@ TZCRYPT_Result SecEncryptTZCrypt(TZCRYPT_UINT8 *Src, TZCRYPT_UINT32 SrcLen, TZCR
* If a given application information (identifier) is wrong, then return UNIT_TEXT_HASH_ERROR
*/
__attribute__((visibility("default")))
-TZCRYPT_Result SecDecryptTZCrypt(TZCRYPT_UINT8 *Src, TZCRYPT_UINT32 SrcLen, TZCRYPT_UINT8 *Dst, TZCRYPT_UINT32 *DstLen, TZCRYPT_UINT8 *AppInfo, TZCRYPT_UINT32 AppInfoLen, TZCRYPT_UINT8 *WrapAppInfo, TZCRYPT_UINT32 WrapAppInfoLen);
+TZCRYPT_Result SecDecryptTZCrypt(TZCRYPT_UINT8 *Src, TZCRYPT_UINT32 SrcLen,
+ TZCRYPT_UINT8 *Dst, TZCRYPT_UINT32 *DstLen, TZCRYPT_UINT8 *AppInfo,
+ TZCRYPT_UINT32 AppInfoLen, TZCRYPT_UINT8 *WrapAppInfo,
+ TZCRYPT_UINT32 WrapAppInfoLen);
/*
* This function provides the length of a given src len
diff --git a/include/device_info.h b/include/device_info.h
index d4c0e24..814839b 100644
--- a/include/device_info.h
+++ b/include/device_info.h
@@ -47,14 +47,14 @@ extern "C" {
* device_id = get_device_id();
* if(device_id == NULL)
* {
- * // Error handling
+ * // Error handling
* }
*
* ...
* @endcode
*
*/
-const char* get_device_id(void);
+const char *get_device_id(void);
#ifdef __cplusplus
}
diff --git a/srcs/SecCryptoSvc.c b/srcs/SecCryptoSvc.c
index 6a146c2..da23ed1 100644
--- a/srcs/SecCryptoSvc.c
+++ b/srcs/SecCryptoSvc.c
@@ -32,15 +32,15 @@
#define CS_API __attribute__((visibility("default")))
-#define SYS_SECBOOT_DEV_ID_LEN 16
-#define NAND_CID_NAME "/sys/block/mmcblk0/device/cid"
-#define NAND_CID_SIZE 32
+#define SYS_SECBOOT_DEV_ID_LEN 16
+#define NAND_CID_NAME "/sys/block/mmcblk0/device/cid"
+#define NAND_CID_SIZE 32
#ifdef CRYPTOSVC_TARGET
-static int __AsciiToHex(const char AsciiHexUpper,const char AsciiHexLower)
+static int __AsciiToHex(const char AsciiHexUpper, const char AsciiHexLower)
{
- char hexReturn=0;
+ char hexReturn = 0;
//First convert upper hex ascii value
if (AsciiHexUpper >= '0' && AsciiHexUpper <= '9')
@@ -65,10 +65,9 @@ static bool OemNandInfoUID(unsigned char *pUID, int nBufferSize)
{
int fd = 0;
char szCID[NAND_CID_SIZE + 1] = {0,};
-
memset(pUID, 0x00, nBufferSize);
-
fd = open(NAND_CID_NAME, O_RDONLY);
+
if (fd < 0) {
SLOGE("cid open error!");
return false;
@@ -91,26 +90,21 @@ static bool OemNandInfoUID(unsigned char *pUID, int nBufferSize)
pUID[14] = __AsciiToHex(szCID[22], szCID[23]);
pUID[13] = __AsciiToHex(szCID[24], szCID[25]);
pUID[12] = __AsciiToHex(szCID[26], szCID[27]);
-
// random permutation
pUID[1] = __AsciiToHex(szCID[2], szCID[3]);
pUID[2] = __AsciiToHex(szCID[6], szCID[7]);
pUID[3] = __AsciiToHex(szCID[8], szCID[9]);
-
pUID[5] = __AsciiToHex(szCID[10], szCID[11]);
pUID[6] = __AsciiToHex(szCID[12], szCID[13]);
pUID[7] = __AsciiToHex(szCID[14], szCID[15]);
-
pUID[9] = __AsciiToHex(szCID[16], szCID[17]);
pUID[10] = __AsciiToHex(szCID[28], szCID[29]);
pUID[11] = __AsciiToHex(szCID[30], szCID[31]);
-
SLOGD(" UID : %8X %8X %8X %8X",
- *(int *)pUID,
- *(int *)(pUID + 4),
- *(int *)(pUID + 8),
- *(int *)(pUID + 12));
-
+ *(int *)pUID,
+ *(int *)(pUID + 4),
+ *(int *)(pUID + 8),
+ *(int *)(pUID + 12));
close(fd);
return true;
}
@@ -134,16 +128,13 @@ bool SecFrameGeneratePlatformUniqueKey(unsigned int uLen, unsigned char *pCek)
int nHashLen = 0;
int remain = 0;
unsigned char *result = NULL;
-
#ifdef CRYPTOSVC_TARGET
SysSecBootGetDeviceUniqueKey(Key);
#else
memset(Key, 0xFF, nTempLen);
#endif
-
- memcpy(Key+nTempLen, SEC_FRAME_OSP_KEY, 9);
+ memcpy(Key + nTempLen, SEC_FRAME_OSP_KEY, 9);
nTempLen += 9;
-
remain = uLen;
for (i = 0; i < uLen; i += HASH_LEN) {
@@ -169,7 +160,6 @@ bool SecFrameGeneratePlatformUniqueKey(unsigned int uLen, unsigned char *pCek)
}
SLOGD("SecFrameGeneratePlatformUniqueKey Success.");
-
ERR:
return bResult;
}
@@ -180,8 +170,8 @@ char *Base64Encoding(const char *data, int size)
char *pEncodedBuf = NULL;
const char *pPointer = NULL;
const char *pLength = data + size - 1;
- unsigned char pInput[3] = {0,0,0};
- unsigned char poutput[4] = {0,0,0,0};
+ unsigned char pInput[3] = {0, 0, 0};
+ unsigned char poutput[4] = {0, 0, 0, 0};
int index = 0;
int loopCnt = 0;
int stringCnt = 0;
@@ -201,18 +191,15 @@ char *Base64Encoding(const char *data, int size)
poutput[1] = ((pInput[0] & 0x3) << 4) | ((pInput[1] & 0xF0) >> 4);
poutput[2] = ((pInput[1] & 0xF) << 2) | ((pInput[2] & 0xC0) >> 6);
poutput[3] = (pInput[2] & 0x3F);
-
pEncodedBuf[stringCnt++] = Base64EncodingTable[poutput[0]];
pEncodedBuf[stringCnt++] = Base64EncodingTable[poutput[1]];
pEncodedBuf[stringCnt++] = index == 0 ? '=' : Base64EncodingTable[poutput[2]];
pEncodedBuf[stringCnt++] = index < 2 ? '=' : Base64EncodingTable[poutput[3]];
-
pInput[0] = pInput[1] = pInput[2] = 0;
}
}
pEncodedBuf[stringCnt] = '\0';
-
return pEncodedBuf;
}
@@ -221,7 +208,6 @@ char *GetDuid(int idSize)
{
const char *version = "1.0#";
char info[] = {0xca, 0xfe, 0xbe, 0xbe, 0x78, 0x07, 0x02, 0x03};
-
unsigned char *pKey = NULL;
unsigned char *pDuid = NULL;
char *pId = NULL;
@@ -254,23 +240,24 @@ char *GetDuid(int idSize)
goto exit;
}
- if (!(pKeyVersion = (char *)calloc(strlen(pId) + strlen(version) + 1, sizeof(char)))) {
+ if (!(pKeyVersion = (char *)calloc(strlen(pId) + strlen(version) + 1,
+ sizeof(char)))) {
SLOGE("Failed to allocate memory");
goto exit;
}
+
strncpy(pKeyVersion, version, strlen(version));
strncat(pKeyVersion, pId, strlen(pId));
-
exit:
free(pKey);
free(pDuid);
free(pId);
-
return pKeyVersion;
}
CS_API
-int cs_derive_key_with_pass(const char *pass, int passlen, int keylen, unsigned char **key)
+int cs_derive_key_with_pass(const char *pass, int passlen, int keylen,
+ unsigned char **key)
{
const int PBKDF_ITERATE_NUM = 1;
unsigned char *platform_key = NULL;
@@ -281,6 +268,7 @@ int cs_derive_key_with_pass(const char *pass, int passlen, int keylen, unsigned
return CS_ERROR_INVALID_PARAM;
platform_key = (unsigned char *)malloc(sizeof(unsigned char) * keylen);
+
if (platform_key == NULL)
return CS_ERROR_BAD_ALLOC;
@@ -290,29 +278,27 @@ int cs_derive_key_with_pass(const char *pass, int passlen, int keylen, unsigned
}
derived_key = (unsigned char *)malloc(sizeof(unsigned char) * keylen);
+
if (derived_key == NULL) {
retval = CS_ERROR_BAD_ALLOC;
goto exit;
}
retval = PKCS5_PBKDF2_HMAC(pass, passlen,
- platform_key, keylen,
- PBKDF_ITERATE_NUM, EVP_sha1(),
- keylen, derived_key);
+ platform_key, keylen,
+ PBKDF_ITERATE_NUM, EVP_sha1(),
+ keylen, derived_key);
+
if (retval != 1) {
retval = CS_ERROR_INTERNAL;
goto exit;
}
free(platform_key);
-
*key = derived_key;
-
return CS_ERROR_NONE;
-
exit:
free(platform_key);
free(derived_key);
-
return retval;
}
diff --git a/srcs/device_info.c b/srcs/device_info.c
index b15ef5a..dc4b7ff 100644
--- a/srcs/device_info.c
+++ b/srcs/device_info.c
@@ -32,14 +32,15 @@
#define TIZENID_STRING "http://tizen.org/system/tizenid"
-char* _device_id = NULL;
+char *_device_id = NULL;
int _is_loaded = false;
pthread_once_t _load_once_block = PTHREAD_ONCE_INIT;
void load_device_id(void)
{
if (!_device_id
- && system_info_get_platform_string(TIZENID_STRING, &_device_id) != SYSTEM_INFO_ERROR_NONE) {
+ && system_info_get_platform_string(TIZENID_STRING,
+ &_device_id) != SYSTEM_INFO_ERROR_NONE) {
SECURE_LOGE("Failed to generate DUID.");
return;
}
@@ -53,9 +54,10 @@ const char *get_device_id(void)
{
if (!_is_loaded) {
pthread_once(&_load_once_block, load_device_id);
+
if (!_is_loaded
- || !_device_id
- || !strlen(_device_id)) {
+ || !_device_id
+ || !strlen(_device_id)) {
LOGE("failed to get device id");
_load_once_block = PTHREAD_ONCE_INIT;
return NULL;
diff --git a/test/colour_log_formatter.h b/test/colour_log_formatter.h
index 193bb94..224898d 100644
--- a/test/colour_log_formatter.h
+++ b/test/colour_log_formatter.h
@@ -18,53 +18,53 @@
namespace cryptsvc {
class colour_log_formatter : public boost::unit_test::unit_test_log_formatter {
public:
- // Formatter interface
- colour_log_formatter() : m_isTestCaseFailed(false) {}
- void log_start(
- std::ostream&,
- boost::unit_test::counter_t test_cases_amount );
- void log_finish( std::ostream& );
- void log_build_info( std::ostream& );
+ // Formatter interface
+ colour_log_formatter() : m_isTestCaseFailed(false) {}
+ void log_start(
+ std::ostream &,
+ boost::unit_test::counter_t test_cases_amount);
+ void log_finish(std::ostream &);
+ void log_build_info(std::ostream &);
- void test_unit_start(
- std::ostream&,
- boost::unit_test::test_unit const& tu );
- void test_unit_finish(
- std::ostream&,
- boost::unit_test::test_unit const& tu,
- unsigned long elapsed );
- void test_unit_skipped(
- std::ostream&,
- boost::unit_test::test_unit const& tu );
+ void test_unit_start(
+ std::ostream &,
+ boost::unit_test::test_unit const &tu);
+ void test_unit_finish(
+ std::ostream &,
+ boost::unit_test::test_unit const &tu,
+ unsigned long elapsed);
+ void test_unit_skipped(
+ std::ostream &,
+ boost::unit_test::test_unit const &tu);
- void log_exception_start(
- std::ostream&,
- boost::unit_test::log_checkpoint_data const&,
- boost::execution_exception const& ex);
- void log_exception_finish(
- std::ostream&);
+ void log_exception_start(
+ std::ostream &,
+ boost::unit_test::log_checkpoint_data const &,
+ boost::execution_exception const &ex);
+ void log_exception_finish(
+ std::ostream &);
- void log_entry_start(
- std::ostream&,
- boost::unit_test::log_entry_data const&,
- log_entry_types let );
- void log_entry_value(
- std::ostream&,
- boost::unit_test::const_string value );
- void log_entry_value(
- std::ostream&,
- boost::unit_test::lazy_ostream const& value );
- void log_entry_finish( std::ostream& );
+ void log_entry_start(
+ std::ostream &,
+ boost::unit_test::log_entry_data const &,
+ log_entry_types let);
+ void log_entry_value(
+ std::ostream &,
+ boost::unit_test::const_string value);
+ void log_entry_value(
+ std::ostream &,
+ boost::unit_test::lazy_ostream const &value);
+ void log_entry_finish(std::ostream &);
- void entry_context_start(
- std::ostream&,
- boost::unit_test::log_level l);
- void log_entry_context(
- std::ostream&,
- boost::unit_test::const_string value);
- void entry_context_finish(std::ostream&);
+ void entry_context_start(
+ std::ostream &,
+ boost::unit_test::log_level l);
+ void log_entry_context(
+ std::ostream &,
+ boost::unit_test::const_string value);
+ void entry_context_finish(std::ostream &);
private:
- bool m_isTestCaseFailed;
+ bool m_isTestCaseFailed;
};
} // namespace cryptsvc