Version 0.1.18
[platform/core/security/key-manager.git] / src / manager / crypto / sw-backend / obj.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       obj.h
18  * @author     BartÅ‚omiej Grzelewski (b.grzelewski@samsung.com)
19  * @version    1.0
20  */
21 #pragma once
22 #include <memory>
23
24 #include <openssl/evp.h>
25
26 #include <generic-backend/gobj.h>
27 #include <data-type.h>
28
29 namespace CKM {
30 namespace Crypto {
31 namespace SW {
32
33 typedef std::unique_ptr<EVP_PKEY_CTX,std::function<void(EVP_PKEY_CTX*)>> ContextUPtr;
34 typedef std::shared_ptr<EVP_PKEY> EvpShPtr;
35
36 class BData : public GObj {
37 public:
38     BData(RawBuffer buffer, DataType keyType)
39       : m_raw(std::move(buffer))
40       , m_type(keyType)
41     {}
42
43     virtual RawBuffer getBinary() const;
44 protected:
45     RawBuffer m_raw;
46     DataType m_type;
47 };
48
49 class SKey : public BData {
50 public:
51     SKey(RawBuffer buffer, DataType keyType) : BData(std::move(buffer), keyType)
52     {}
53
54     virtual RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &);
55     virtual RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &);
56 };
57
58 class AKey : public BData {
59 public:
60     AKey(RawBuffer buffer, DataType dataType) : BData(std::move(buffer), dataType)
61     {}
62     virtual RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message);
63     virtual int verify(const CryptoAlgorithm &alg, const RawBuffer &message, const RawBuffer &sign);
64     virtual RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &);
65     virtual RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &);
66     virtual ~AKey(){}
67 protected:
68     virtual EvpShPtr getEvpShPtr();
69
70     EvpShPtr m_evp;
71 };
72
73 class Cert : public AKey {
74 public:
75     Cert(RawBuffer buffer, DataType dataType)
76       : AKey(std::move(buffer), dataType)
77     {}
78     virtual ~Cert(){}
79 protected:
80     virtual EvpShPtr getEvpShPtr();
81 };
82
83 } // namespace SW
84 } // namespace Crypto
85 } // namespace CKM
86