94182f58cef408b81ec06b4a3af0402e7232df21
[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 //#ifdef OPENSSL_NO_ENGINE
29 //#error Do not use define <OPENSSL_NO_ENGINE>
30 //#else
31 #include <openssl/engine.h>
32 //#endif
33
34 /*typedef enum
35 {
36         SEC_CRYPTO_CIPHER_NULL = 0,
37         SEC_CRYPTO_CIPHER_AES_CBC_128,
38         SEC_CRYPTO_CIPHER_SEED_CBC,
39         SEC_CRYPTO_CIPHER_AES_CBC_192,
40         SEC_CRYPTO_CIPHER_AES_CBC_256,
41         SEC_CRYPTO_CIPHER_AES_CTR_128,
42         SEC_CRYPTO_CIPHER_AES_ECB_128,
43         SEC_CRYPTO_CIPHER_AES_ECB_192,
44         SEC_CRYPTO_CIPHER_AES_ECB_256
45 } SecCryptoCipherAlg;
46
47 typedef enum
48 {
49         SEC_SUCCESS = 0,
50         SEC_CRYPTO_ERROR_1, //algorithm error
51         SEC_CRYPTO_ERROR_2, //init error
52         SEC_CRYPTO_ERROR_3, //update error
53         SEC_CRYPTO_ERROR_4, //final error
54         SEC_CRYPTO_ERROR_5, //wrong param
55         SEC_CRYPTO_ERROR_6, //Memory alloc
56         SEC_CRYPTO_ERROR_7, //Internal error
57 } SecError;
58 */
59 //#ifndef bool
60 #ifdef _bool_cryptsvc
61 typedef enum {false, true} bool;
62 #endif
63
64 #ifndef IN
65 #define IN
66 #endif
67 #ifndef OUT
68 #define OUT
69 #endif
70
71 #ifndef NULL
72 #define NULL 0
73 #endif
74 #ifndef BOOL
75 #define BOOL bool
76 #endif
77 #ifndef ULONG
78 #define ULONG unsigned int
79 #endif
80 #ifndef UINT8
81 #define UINT8 unsigned char
82 #endif
83 #ifndef UINT32
84 #define UINT32 unsigned int
85 #endif
86
87 //#define EVP_ERROR                     0
88 //#define SEC_CRYPTO_ENCRYPT            1
89 //#define SEC_CRYPTO_DECRYPT            0
90 #define SEC_DUK_SIZE                    16
91 //#define SEC_CRYPTO_KEY_LENGTH         16
92 //#define SEC_CRYPTP_ARR_LENGTH         1024
93 #define SEC_FRAME_OSP_KEY               "uniqueKey"
94 //#define SHA1_DIGEST_VALUE_LEN         20
95 #define SHA256_DIGEST_VALUE_LEN         32
96 //#define KDF_KEYLEN                    16
97 #define HASH_LEN                        20
98 //#define SEC_KEYMGR_FEK_SIZE           16
99
100 /*------ Base64 Encoding Table ------*/
101 static const char Base64EncodingTable[] = {
102     'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
103     'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P',
104     'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X',
105     'Y', 'Z', 'a', 'b', 'c', 'd', 'e', 'f',
106     'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n',
107     'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
108     'w', 'x', 'y', 'z', '0', '1', '2', '3',
109         '4', '5', '6', '7', '8', '9', '+', '/'
110 };
111
112 /**
113         * This function provides Device UniqueKey for crypto with Hash
114         * @return               This function returns TRUE on success
115         * @param[in]            uLen    Length of Device UniqueKey
116         * @param[in,out]        pCek    Device UniqueKey(Hashed)
117 */
118 __attribute__((visibility("default")))
119 bool SecFrameGeneratePlatformUniqueKey(IN UINT32  uLen,IN OUT UINT8  *pCek);
120
121 __attribute__((visibility("default")))
122 char* Base64Encoding(char* pData, int size);
123
124 __attribute__((visibility("default")))
125 char* GetDuid(int size);
126
127 #ifdef __cplusplus
128 }
129 #endif
130
131 #endif  // _SEC_CRYPTO_SVC_H
132