2 * Copyright (c) 2000 - 2013 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 Bartlomiej Grzelewski (b.grzelewski@samsung.com)
20 * @brief Sample service implementation.
31 #include <ckm/ckm-raw-buffer.h>
32 #include <ckm/ckm-password.h>
34 #define KEY_MANAGER_API __attribute__((visibility("default")))
38 // used to pass password and raw key data
39 typedef std::vector<RawBuffer> RawBufferVector;
40 typedef std::string Alias;
41 typedef std::string Label;
42 typedef std::vector<Alias> AliasVector;
44 enum class KeyType : int {
55 enum class DataFormat : int {
61 enum class ElipticCurve : int {
67 enum class CertificateFieldId : int {
73 Policy(const Password &pass = Password(), bool extract = true)
75 , extractable(extract)
78 Password password; // byte array used to encrypt data inside CKM
79 bool extractable; // if true key may be extracted from storage
82 enum class HashAlgorithm : int {
90 enum class RSAPaddingAlgorithm : int {
96 enum class DBCMAlgType : int {
102 typedef int PermissionMask;
103 enum Permission: int {
107 // keep in sync with ckmc_permission_e !
110 const char * ErrorToString(int error);
112 // algorithm parameters
113 enum class ParamName : int {
114 ALGO_TYPE = 1, // If there's no such param, the service will try to deduce the algorithm
115 // type from the key.
117 // encryption & decryption
127 GEN_EC, // elliptic curve (ElipticCurve)
130 SV_HASH_ALGO = 301, // hash algorithm (HashAlgorithm)
131 SV_RSA_PADDING, // RSA padding (RSAPaddingAlgorithm)
134 // algorithm types (ALGO_TYPE param)
135 enum class AlgoType : int {
146 // cryptographic algorithm description
147 class KEY_MANAGER_API CryptoAlgorithm {
149 template <typename T>
150 bool getParam(ParamName name, T& value) const;
152 // returns false if param 'name' already exists
153 template <typename T>
154 bool addParam(ParamName name, const T& value);
159 virtual bool getBuffer(RawBuffer&) const { return false; }
160 virtual bool getInt(uint64_t&) const { return false; }
161 virtual ~BaseParam() {}
166 typedef std::unique_ptr<BaseParam> BaseParamPtr;
168 class BufferParam : public BaseParam {
170 bool getBuffer(RawBuffer& buffer) const;
171 static BaseParamPtr create(const RawBuffer& buffer);
173 explicit BufferParam(const RawBuffer& value) : m_buffer(value) {}
178 class IntParam : public BaseParam {
180 static BaseParamPtr create(uint64_t value);
181 bool getInt(uint64_t& value) const;
183 explicit IntParam(uint64_t value) : m_int(value) {}
188 std::map<ParamName, BaseParamPtr> m_params;