Change code formatting in import/export wrapped key
[platform/core/security/key-manager.git] / src / manager / crypto / sw-backend / obj.h
1 /*
2  *  Copyright (c) 2000-2020 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       obj.h
18  * @author     BartÅ‚omiej Grzelewski (b.grzelewski@samsung.com)
19  * @version    1.0
20  */
21 #pragma once
22 #include <functional>
23 #include <memory>
24
25 #include <openssl/evp.h>
26
27 #include <generic-backend/gobj.h>
28 #include <generic-backend/gstore.h>
29 #include <data-type.h>
30
31 namespace CKM {
32 namespace Crypto {
33 namespace SW {
34
35 typedef std::shared_ptr<EVP_PKEY> EvpShPtr;
36
37 class BData : public GObj {
38 public:
39         BData(CryptoBackend backendId, RawBuffer buffer, DataType keyType) :
40                 GObj(backendId), m_raw(std::move(buffer)), m_type(keyType) {}
41
42         RawBuffer getBinary() const override
43         {
44                 return m_raw;
45         }
46         Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
47
48 protected:
49         RawBuffer m_raw;
50         DataType m_type;
51 };
52
53 class Key : public BData {
54         using BData::BData;
55
56         Token unwrap(const CryptoAlgorithm &params,
57                                  const Data &wrappedKey,
58                                  const Password &pass,
59                                  const RawBuffer &hash) override;
60
61         RawBuffer wrap(const CryptoAlgorithm &params,
62                                    const Token &keyToWrap,
63                                    const Password &keyToWrapPass) override;
64
65 };
66
67 class SKey : public Key {
68 public:
69         using Key::Key;
70
71         RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
72         RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
73 };
74
75 class AKey : public Key {
76 public:
77         using Key::Key;
78
79         RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message) override;
80         int verify(const CryptoAlgorithm &alg,
81                    const RawBuffer &message,
82                    const RawBuffer &sign) override;
83         RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
84         RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
85         Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
86
87 protected:
88         virtual EvpShPtr getEvpShPtr();
89
90         EvpShPtr m_evp;
91 };
92
93 class Cert : public AKey {
94 public:
95         using AKey::AKey;
96
97         Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
98         Token unwrap(const CryptoAlgorithm &,
99                                  const Data &,
100                                  const Password &,
101                                  const RawBuffer &) override;
102
103         RawBuffer wrap(const CryptoAlgorithm &,
104                                    const Token &,
105                                    const Password &) override;
106
107 protected:
108         EvpShPtr getEvpShPtr() override;
109 };
110
111 } // namespace SW
112 } // namespace Crypto
113 } // namespace CKM
114