replace : iotivity -> iotivity-sec
[platform/upstream/iotivity.git] / resource / csdk / security / include / internal / psiutils.h
1 //******************************************************************
2 //
3 // Copyright 2017 Samsung Electronics All Rights Reserved.
4 //
5 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
6 //
7 // Licensed under the Apache License, Version 2.0 (the "License");
8 // you may not use this file except in compliance with the License.
9 // You may obtain a copy of the License at
10 //
11 //      http://www.apache.org/licenses/LICENSE-2.0
12 //
13 // Unless required by applicable law or agreed to in writing, software
14 // distributed under the License is distributed on an "AS IS" BASIS,
15 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 // See the License for the specific language governing permissions and
17 // limitations under the License.
18 //
19 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
20
21 #ifndef IOTVT_SRM_PSIUTILS_H
22 #define IOTVT_SRM_PSIUTILS_H
23
24 #define AES_KEY_SIZE 32
25
26 /**
27  * @brief Generic Encryption function to encrypt data buffer in plaintext
28  * and update in ciphertext and len in ct_len. (AES-CBC-HMAC)
29  * @param[in] plaintext plaintext to be encrypted
30  * @param[in] pt_len length of plaintext
31  * @param[out] ciphertext ciphered text
32  * @param[out] ct_len is length of the ciphered text.
33  *
34  * @return ::0 for Success.
35  */
36 int psiEncrypt(const unsigned char *plaintext, size_t pt_len,
37                 unsigned char **ciphertext, size_t *ct_len);
38
39 /**
40  * @brief Generic Decryption function to decrypt data buffer in ciphertext
41  * and update in plaintext and len in pt_len. (AES-CBC-HMAC)
42  * @param[in] ciphertext ciphered to be decrypted
43  * @param[in] ct_len length of cipher text
44  * @param[out] plaintext plaintext text
45  * @param[out] pt_len is length of the plaintext text.
46  *
47  * @return ::0 for Success.
48  */
49 int psiDecrypt(const unsigned char *ciphertext, size_t ct_len,
50                 unsigned char **plaintext, size_t *pt_len);
51
52 /**
53  * @brief API to set key to psi
54  * @param[in] key key used for encryption
55  * @return ::OC_STACK_OK for Success, otherwise some error value.
56  */
57 OCStackResult psiSetKey(const unsigned char* key);
58
59 /**
60  * @brief API to get key from psi
61  * @param[out] key key used for encryption
62  * @return ::OC_STACK_OK for Success, otherwise some error value.
63  */
64 OCStackResult psiGetKey(unsigned char* key);
65
66 /**
67  * @brief It provides state to set key for encryption
68  * @return ::true for setting key.
69  */
70 bool psiIsKeySet();
71
72 #endif //IOTVT_SRM_PSIUTILS_H