Refactor build system and add internal test
[platform/core/security/libcryptsvc.git] / include / SecCryptoSvc.h
1 /*
2  * libcryptsvc - device unique key
3  *
4  * Copyright (c) 2000 - 2013 Samsung Electronics Co., Ltd All Rights Reserved
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #ifndef _SEC_CRYPTO_SVC_H
21 #define _SEC_CRYPTO_SVC_H
22
23 #ifdef __cplusplus
24 extern "C"
25 {
26 #endif
27
28 #include <stdbool.h>
29
30 //#ifdef OPENSSL_NO_ENGINE
31 //#error Do not use define <OPENSSL_NO_ENGINE>
32 //#else
33 #include <openssl/engine.h>
34 //#endif
35
36 /*typedef enum
37 {
38         SEC_CRYPTO_CIPHER_NULL = 0,
39         SEC_CRYPTO_CIPHER_AES_CBC_128,
40         SEC_CRYPTO_CIPHER_SEED_CBC,
41         SEC_CRYPTO_CIPHER_AES_CBC_192,
42         SEC_CRYPTO_CIPHER_AES_CBC_256,
43         SEC_CRYPTO_CIPHER_AES_CTR_128,
44         SEC_CRYPTO_CIPHER_AES_ECB_128,
45         SEC_CRYPTO_CIPHER_AES_ECB_192,
46         SEC_CRYPTO_CIPHER_AES_ECB_256
47 } SecCryptoCipherAlg;
48
49 typedef enum
50 {
51         SEC_SUCCESS = 0,
52         SEC_CRYPTO_ERROR_1, //algorithm error
53         SEC_CRYPTO_ERROR_2, //init error
54         SEC_CRYPTO_ERROR_3, //update error
55         SEC_CRYPTO_ERROR_4, //final error
56         SEC_CRYPTO_ERROR_5, //wrong param
57         SEC_CRYPTO_ERROR_6, //Memory alloc
58         SEC_CRYPTO_ERROR_7, //Internal error
59 } SecError;
60 */
61
62 #ifndef IN
63 #define IN
64 #endif
65 #ifndef OUT
66 #define OUT
67 #endif
68
69 #ifndef NULL
70 #define NULL 0
71 #endif
72 #ifndef BOOL
73 #define BOOL bool
74 #endif
75 #ifndef ULONG
76 #define ULONG unsigned int
77 #endif
78 #ifndef UINT8
79 #define UINT8 unsigned char
80 #endif
81 #ifndef UINT32
82 #define UINT32 unsigned int
83 #endif
84
85 //#define EVP_ERROR                     0
86 //#define SEC_CRYPTO_ENCRYPT            1
87 //#define SEC_CRYPTO_DECRYPT            0
88 #define SEC_DUK_SIZE                    16
89 //#define SEC_CRYPTO_KEY_LENGTH         16
90 //#define SEC_CRYPTP_ARR_LENGTH         1024
91 #define SEC_FRAME_OSP_KEY               "uniqueKey"
92 //#define SHA1_DIGEST_VALUE_LEN         20
93 #define SHA256_DIGEST_VALUE_LEN         32
94 //#define KDF_KEYLEN                    16
95 #define HASH_LEN                        20
96 //#define SEC_KEYMGR_FEK_SIZE           16
97
98 /*------ Base64 Encoding Table ------*/
99 static const char Base64EncodingTable[] = {
100     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
101     'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
102     'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
103     'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
104     'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
105     'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
106     'w', 'x', 'y', 'z', '0', '1', '2', '3',
107         '4', '5', '6', '7', '8', '9', '+', '/'
108 };
109
110 /**
111         * This function provides Device UniqueKey for crypto with Hash
112         * @return               This function returns TRUE on success
113         * @param[in]            uLen    Length of Device UniqueKey
114         * @param[in,out]        pCek    Device UniqueKey(Hashed)
115 */
116 __attribute__((visibility("default")))
117 bool SecFrameGeneratePlatformUniqueKey(IN UINT32  uLen,IN OUT UINT8  *pCek);
118
119 __attribute__((visibility("default")))
120 char* Base64Encoding(char* pData, int size);
121
122 __attribute__((visibility("default")))
123 char* GetDuid(int size);
124
125 #ifdef __cplusplus
126 }
127 #endif
128
129 #endif  // _SEC_CRYPTO_SVC_H
130