65472e4c25d2e6a20d94c5c572277700f4f93eaa
[platform/core/security/ode.git] / server / engine / dmcrypt-engine.h
1 /*
2  *  Copyright (c) 2016 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 #ifndef __DMCRYPT_ENGINE_H__
18 #define __DMCRYPT_ENGINE_H__
19
20 #include <vector>
21 #include <string>
22
23 #include "progress-bar.h"
24
25 namespace ode {
26
27 class CryptInfo {
28 public:
29         void init(const std::string &src, const std::string &crypto_name);
30         long getFileSystemSize();
31         std::string getCryptoTypeName() const;
32
33 private:
34         long getBlkdevSize(const std::string &src);
35
36 private:
37         // TODO(seok85.hong): support fast-encryption
38         long fs_size;
39         std::string crypto_type_name;
40 };
41
42
43 class DMCryptEngine final {
44 public:
45         DMCryptEngine(const std::string &src, const std::string &dest, const ProgressBar &prgsBar);
46         DMCryptEngine(const DMCryptEngine &) = delete;
47         DMCryptEngine(DMCryptEngine &&) = delete;
48         ~DMCryptEngine();
49
50         DMCryptEngine &operator=(const DMCryptEngine &) = delete;
51         DMCryptEngine &operator=(DMCryptEngine &&) = delete;
52
53         const std::string &getSource()
54         {
55                 return source;
56         }
57
58         const std::string &getDestination()
59         {
60                 return destination;
61         }
62
63         typedef std::vector<unsigned char> data;
64
65         void mount(const data &key, unsigned int options);
66         void umount();
67
68         void encrypt(const data &key, unsigned int options);
69         void decrypt(const data &key, unsigned int options);
70
71         const data getKeyMeta();
72         void setKeyMeta(const data &data);
73
74         unsigned int getSupportedOptions();
75
76 private:
77         void encryptInPlace(const std::string &dst_blkdev,
78                                                 const std::string &src_blkdev,
79                                                 const long src_blkdev_size);
80
81 private:
82         std::string source, destination;
83         CryptInfo cryptInfo;
84         ProgressBar progressBar;
85 };
86
87 } // namespace ode
88 #endif // __DMCRYPT_ENGINE_H__