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 <data-type.h>
33 Pwd(Password pwd, RawBuffer iv, RawBuffer tag)
34 : m_password(pwd.begin(), pwd.end())
36 , m_tag(std::move(tag))
39 const RawBuffer& getPassword() const
44 const RawBuffer& getIV() const
49 const RawBuffer& getTag() const
61 class BData : public GObj {
63 explicit BData(CryptoBackend backendId, RawBuffer buffer) :
64 GObj(backendId), m_raw(std::move(buffer)) {}
66 RawBuffer getBinary() const override
70 Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
76 class Key : public BData {
78 Key(CryptoBackend backendId, int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
79 BData(backendId, std::move(buffer)),
81 m_password(std::move(pwd)),
84 virtual int getScheme() const
89 virtual Pwd getPassword() const
94 Token unwrap(const CryptoAlgorithm ¶ms,
95 const Data &encryptedKey,
97 const RawBuffer &hash) override;
99 RawBuffer wrap(const CryptoAlgorithm ¶ms,
100 const Token &keyToWrap,
101 const Password &keyToWrapPass) override;
109 class SKey : public Key {
111 SKey(CryptoBackend backendId, int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
112 Key(backendId, scheme, std::move(buffer), std::move(pwd), dataType) {}
114 RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
115 RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
118 class AKey : public Key {
120 AKey(CryptoBackend backendId, int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
121 Key(backendId, scheme, std::move(buffer), std::move(pwd), dataType) {}
123 RawBuffer sign(const CryptoAlgorithm &alg, const RawBuffer &message) override;
124 int verify(const CryptoAlgorithm &alg, const RawBuffer &message,
125 const RawBuffer &sign) override;
126 RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
127 RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
128 Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
131 class Cert : public AKey {
133 Cert(CryptoBackend backendId, int scheme, RawBuffer buffer, Pwd pwd, DataType dataType) :
134 AKey(backendId, scheme, std::move(buffer), std::move(pwd), dataType) {}
136 Token unwrap(const CryptoAlgorithm &,
139 const RawBuffer &) override;
141 RawBuffer wrap(const CryptoAlgorithm ¶ms,
142 const Token &keyToWrap,
143 const Password &keyToWrapPass) override;
147 } // namespace Crypto