2 * Copyright (c) 2015 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
18 * @author Lukasz Kostyra (l.kostyra@samsung.com)
23 #include <generic-backend/gobj.h>
24 #include <generic-backend/gstore.h>
25 #include <generic-backend/gctx.h>
26 #include <data-type.h>
34 Pwd(Password pwd, RawBuffer iv, RawBuffer tag)
35 : m_password(pwd.begin(), pwd.end())
37 , m_tag(std::move(tag))
40 const RawBuffer& getPassword() const
45 const RawBuffer& getIV() const
50 const RawBuffer& getTag() const
61 class BData : public GObj {
63 BData(CryptoBackend backendId,
67 RawBuffer buffer = RawBuffer()) :
70 m_password(std::move(pwd)),
72 m_raw(std::move(buffer)) {}
74 RawBuffer getBinary() const override
78 virtual const RawBuffer& getId() const
82 virtual int getScheme() const
86 virtual const Pwd& getPassword() const
90 Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
99 class Key : public BData {
101 Key(CryptoBackend backendId, int scheme, RawBuffer id, Pwd pwd) :
102 BData(backendId, scheme, std::move(id), std::move(pwd)) {}
104 Token unwrap(const CryptoAlgorithm ¶ms,
105 const Data &encryptedKey,
106 const Password &pass,
107 const RawBuffer &hash) override;
109 RawBuffer wrap(const CryptoAlgorithm ¶ms,
110 const Token &keyToWrap,
111 const Password &keyToWrapPass) override;
114 class SKey : public Key {
116 SKey(CryptoBackend backendId, int scheme, RawBuffer id, Pwd pwd) :
117 Key(backendId, scheme, std::move(id), std::move(pwd)) {}
119 RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
120 RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
121 GCtxShPtr initContext(const CryptoAlgorithm &, bool) override;
124 class AKey : public Key {
126 AKey(CryptoBackend backendId,
131 RawBuffer raw = RawBuffer()) :
132 Key(backendId, scheme, std::move(id), std::move(pwd)), m_type(dataType)
134 m_raw = std::move(raw);
137 RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message) override;
138 int verify(const CryptoAlgorithm &alg, const RawBuffer &message,
139 const RawBuffer &sign) override;
140 RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
141 RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
142 Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
143 GCtxShPtr initContext(const CryptoAlgorithm &, bool) override;
149 class Cert : public AKey {
151 Cert(CryptoBackend backendId, int scheme, RawBuffer id, Pwd pwd, DataType dataType) :
152 AKey(backendId, scheme, std::move(id), std::move(pwd), dataType) {}
154 Token unwrap(const CryptoAlgorithm &,
157 const RawBuffer &) override;
159 RawBuffer wrap(const CryptoAlgorithm ¶ms,
160 const Token &keyToWrap,
161 const Password &keyToWrapPass) override;
165 } // namespace Crypto