2 * Copyright (c) 2000-2020 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 Bartłomiej Grzelewski (b.grzelewski@samsung.com)
25 #include <openssl/evp.h>
27 #include <generic-backend/gobj.h>
28 #include <generic-backend/gstore.h>
29 #include <data-type.h>
35 typedef std::shared_ptr<EVP_PKEY> EvpShPtr;
37 class BData : public GObj {
39 BData(CryptoBackend backendId, RawBuffer buffer, DataType keyType) :
40 GObj(backendId), m_raw(std::move(buffer)), m_type(keyType) {}
42 RawBuffer getBinary() const override
46 Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
53 class Key : public BData {
56 Token unwrap(const CryptoAlgorithm ¶ms,
57 const Data &wrappedKey,
59 const RawBuffer &hash) override;
61 RawBuffer wrap(const CryptoAlgorithm ¶ms,
62 const Token &keyToWrap,
63 const Password &keyToWrapPass) override;
67 class SKey : public Key {
71 RawBuffer encrypt(const CryptoAlgorithm &, const RawBuffer &) override;
72 RawBuffer decrypt(const CryptoAlgorithm &, const RawBuffer &) override;
75 class AKey : public Key {
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;
88 virtual EvpShPtr getEvpShPtr();
93 class Cert : public AKey {
97 Token derive(const CryptoAlgorithm &, const Password &, const RawBuffer &) override;
98 Token unwrap(const CryptoAlgorithm &,
101 const RawBuffer &) override;
103 RawBuffer wrap(const CryptoAlgorithm &,
105 const Password &) override;
108 EvpShPtr getEvpShPtr() override;
112 } // namespace Crypto