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