Add classes for algorithm parameters 57/39057/3
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 7 May 2015 15:38:24 +0000 (17:38 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Fri, 8 May 2015 13:50:29 +0000 (15:50 +0200)
[Issue#] N/A
[Feature/Bug] N/A
[Problem] N/A
[Cause] We need a way to represent different algorithm parameters in a common
way.
[Solution] A set of classes and enums added.

[Verification] Run ckm-tests --group=ALGO_PARAM_TEST

Change-Id: I281a1b192d01bad5bdfded8dbb1d385e876b6657

src/include/ckm/ckm-type.h
src/manager/CMakeLists.txt
src/manager/common/algo-param.cpp [new file with mode: 0644]

index 53b87a7..95233d8 100644 (file)
  */
 #pragma once
 
+#include <stdint.h>
+
 #include <string>
 #include <vector>
+#include <map>
+#include <memory>
 
 #include <ckm/ckm-raw-buffer.h>
 #include <ckm/ckm-password.h>
@@ -105,5 +109,73 @@ enum Permission: int {
 
 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
 
index a84dce3..9cfea7e 100644 (file)
@@ -13,6 +13,7 @@ SET(KEY_MANAGER_COMMON_VERSION ${KEY_MANAGER_COMMON_VERSION_MAJOR}.0.1)
 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
diff --git a/src/manager/common/algo-param.cpp b/src/manager/common/algo-param.cpp
new file mode 100644 (file)
index 0000000..e0a72c9
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ *  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