2 * Copyright (c) 2000 - 2019 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #ifndef _SEC_CRYPTO_SVC_H
19 #define _SEC_CRYPTO_SVC_H
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
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
68 #define ULONG unsigned int
71 #define UINT8 unsigned char
74 #define UINT32 unsigned int
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
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
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', '+', '/'
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)
113 bool SecFrameGeneratePlatformUniqueKey(IN UINT32 uLen, IN OUT UINT8 *pCek);
115 char *Base64Encoding(const char *data, int size);
117 char *GetDuid(int size);
120 * Password based derivation routines with platform key
122 * @remarks Returned @a key should be freed by caller after use.
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
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
136 int cs_derive_key_with_pass(const char *pass, int passlen, int keylen,
137 unsigned char **key);
143 #endif // _SEC_CRYPTO_SVC_H