*/
#pragma once
+#include <stdint.h>
+
#include <string>
#include <vector>
+#include <map>
+#include <memory>
#include <ckm/ckm-raw-buffer.h>
#include <ckm/ckm-password.h>
const char * ErrorToString(int error);
+// algorithm parameters
+enum class ParamName : int {
+ // encryption & decryption
+ ED_IV = 1,
+ ED_CTR,
+ ED_CTR_LEN,
+ ED_AAD,
+ ED_TAG_LEN,
+ ED_LABEL,
+
+ // key generation
+ GEN_KEY_LEN = 101,
+ GEN_EC, // elliptic curve (ElipticCurve)
+
+ // sign & verify
+ SV_HASH_ALGO = 201, // hash algorithm (HashAlgorithm)
+ SV_RSA_PADDING, // RSA padding (RSAPaddingAlgorithm)
+};
+
+// algorithm types
+enum class AlgoType : int {
+ AES_CTR = 1,
+ AES_CBC,
+ AES_GCM,
+ AES_CFB,
+ RSA_OAEP,
+ RSA,
+ DSA,
+ ECDSA,
+};
+
+class KEY_MANAGER_API BaseParam {
+public:
+ virtual int getBuffer(RawBuffer&) const;
+ virtual int getInt(uint64_t&) const;
+ virtual ~BaseParam() {}
+
+protected:
+ BaseParam() {}
+};
+typedef std::unique_ptr<BaseParam> BaseParamPtr;
+
+class KEY_MANAGER_API BufferParam : public BaseParam {
+public:
+ int getBuffer(RawBuffer& buffer) const;
+ static BaseParamPtr create(const RawBuffer& buffer);
+private:
+ explicit BufferParam(const RawBuffer& value) : m_buffer(value) {}
+
+ RawBuffer m_buffer;
+};
+
+class KEY_MANAGER_API IntParam : public BaseParam {
+public:
+ static BaseParamPtr create(uint64_t value);
+ int getInt(uint64_t& value) const;
+private:
+ explicit IntParam(uint64_t value) : m_int(value) {}
+
+ uint64_t m_int;
+};
+
+// cryptographic algorithm description
+struct CryptoAlgorithm {
+ AlgoType m_type;
+ std::map<ParamName, BaseParamPtr> m_params;
+};
+
} // namespace CKM
SET(COMMON_PATH ${PROJECT_SOURCE_DIR}/src/manager)
SET(COMMON_SOURCES
+ ${COMMON_PATH}/common/algo-param.cpp
${COMMON_PATH}/common/base64.cpp
${COMMON_PATH}/common/crypto-init.cpp
${COMMON_PATH}/common/protocols.cpp
--- /dev/null
+/*
+ * Copyright (c) 2000 - 2015 Samsung Electronics Co., Ltd All Rights Reserved
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+/*
+ * @file algo-param.cpp
+ * @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com)
+ * @version 1.0
+ */
+
+#include <ckm/ckm-type.h>
+#include <ckm/ckm-error.h>
+
+namespace CKM
+{
+
+int BaseParam::getBuffer(RawBuffer&) const
+{
+ return CKM_API_ERROR_INVALID_FORMAT;
+}
+
+int BaseParam::getInt(uint64_t&) const
+{
+ return CKM_API_ERROR_INVALID_FORMAT;
+}
+
+int BufferParam::getBuffer(RawBuffer& buffer) const
+{
+ buffer = m_buffer;
+ return CKM_API_SUCCESS;
+}
+
+BaseParamPtr BufferParam::create(const RawBuffer& buffer)
+{
+ return BaseParamPtr(new BufferParam(buffer));
+}
+
+int IntParam::getInt(uint64_t& value) const
+{
+ value = m_int;
+ return CKM_API_SUCCESS;
+}
+
+BaseParamPtr IntParam::create(uint64_t value)
+{
+ return BaseParamPtr(new IntParam(value));
+}
+
+} // namespace CKM