Use new classes to sign and verify messages.
[platform/core/security/key-manager.git] / src / manager / crypto / sw-backend / key.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       key.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/gkey.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 SKey : public GKey {
37 public:
38     SKey(RawBuffer buffer, DataType keyType)
39       : m_key(std::move(buffer))
40       , m_type(keyType)
41     {}
42 protected:
43     RawBuffer m_key;
44     DataType m_type;
45 };
46
47 class AKey : public GKey {
48 public:
49     AKey(RawBuffer buffer, DataType dataType)
50       : m_key(std::move(buffer))
51       , m_type(dataType)
52     {}
53     virtual RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message);
54     virtual int verify(const CryptoAlgorithm &alg, const RawBuffer &message, const RawBuffer &sign);
55     virtual ~AKey(){}
56 protected:
57     virtual EvpShPtr getEvpShPtr();
58
59     EvpShPtr m_evp;
60     RawBuffer m_key;
61     DataType m_type;
62 };
63
64 class Cert : public AKey {
65 public:
66     Cert(RawBuffer buffer, DataType dataType)
67       : AKey(std::move(buffer), dataType)
68     {}
69     virtual ~Cert(){}
70 protected:
71     virtual EvpShPtr getEvpShPtr();
72 };
73
74 } // namespace SW
75 } // namespace Crypto
76 } // namespace CKM
77