Sw backend ECDH implementation
[platform/core/security/key-manager.git] / src / manager / crypto / sw-backend / internals.h
1 /*
2  *  Copyright (c) 2000 - 2015 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  * @file       internals.h
18  * @author
19  * @version    1.0
20  */
21 #pragma once
22
23 #include <ckm/ckm-type.h>
24 #include <openssl/evp.h>
25 #include <sw-backend/obj.h>
26
27 namespace CKM {
28 namespace Crypto {
29 namespace SW {
30 namespace Internals {
31
32 // TODO replace it with DataContainer
33 struct Data {
34         DataType type;
35         RawBuffer buffer;
36 };
37
38 typedef std::pair<Data, Data> DataPair;
39
40 DataPair generateAKey(const CryptoAlgorithm &algorithm);
41 Data generateSKey(const CryptoAlgorithm &algorithm);
42
43 RawBuffer symmetricEncrypt(
44         const RawBuffer &key,
45         const CryptoAlgorithm &alg,
46         const RawBuffer &data);
47 RawBuffer symmetricDecrypt(
48         const RawBuffer &key,
49         const CryptoAlgorithm &alg,
50         const RawBuffer &cipher);
51 RawBuffer asymmetricEncrypt(
52         const EvpShPtr &key,
53         const CryptoAlgorithm &alg,
54         const RawBuffer &data);
55 RawBuffer asymmetricDecrypt(
56         const EvpShPtr &key,
57         const CryptoAlgorithm &alg,
58         const RawBuffer &data);
59
60 std::pair<RawBuffer, RawBuffer> encryptDataAesGcm(
61         const RawBuffer &key,
62         const RawBuffer &data,
63         const RawBuffer &iv,
64         int tagSize,
65         const RawBuffer &aad = RawBuffer());
66
67 RawBuffer decryptDataAesGcm(
68         const RawBuffer &key,
69         const RawBuffer &data,
70         const RawBuffer &iv,
71         const RawBuffer &tag,
72         const RawBuffer &aad = RawBuffer());
73
74 RawBuffer encryptDataAes(AlgoType type,
75                                                  const RawBuffer &key,
76                                                  const RawBuffer &data,
77                                                  const RawBuffer &iv);
78
79 RawBuffer decryptDataAes(AlgoType type,
80                                                  const RawBuffer &key,
81                                                  const RawBuffer &data,
82                                                  const RawBuffer &iv);
83
84 RawBuffer sign(EVP_PKEY *pkey,
85                            const CryptoAlgorithm &alg,
86                            const RawBuffer &message);
87
88 int verify(EVP_PKEY *pkey,
89                    const CryptoAlgorithm &alg,
90                    const RawBuffer &message,
91                    const RawBuffer &signature);
92
93 Data deriveECDH(const EvpShPtr &pkey, const CryptoAlgorithm &alg);
94
95 } // namespace Internals
96 } // namespace SW
97 } // namespace Crypto
98 } // namespace CKM