Add algorithm param validation
[platform/core/security/key-manager.git] / src / include / ckmc / ckmc-type.h
index 197a02c..a450b86 100644 (file)
@@ -23,6 +23,7 @@
 #define __TIZEN_CORE_CKMC_TYPE_H
 
 #include <stddef.h>
+#include <stdint.h>
 #include <ckmc/ckmc-error.h>
 
 #define KEY_MANAGER_CAPI __attribute__((visibility("default")))
@@ -45,6 +46,15 @@ extern "C" {
 KEY_MANAGER_CAPI extern char const * const ckmc_label_name_separator;
 
 /**
+ * shared database label - user may be given permission to access shared
+ * database items. In such case, the alias should contain shared database
+ * label.
+ * @see ckmc_label_name_separator
+ * @see key-manager_doc.h
+ */
+KEY_MANAGER_CAPI extern char const * const ckmc_label_shared_owner;
+
+/**
  * @brief Enumeration for key types of key manager.
  * @since_tizen 2.3
  */
@@ -209,6 +219,104 @@ typedef struct __ckmc_pkcs12 {
     ckmc_cert_list_s *ca_chain; /**< chain certificates list, may be null */
 } ckmc_pkcs12_s;
 
+/**
+ * @brief Enumeration for crypto algorithm parameters.
+ * @since_tizen 3.0
+ */
+typedef enum __ckmc_param_name {
+    CKMC_PARAM_ALGO_TYPE = 1,
+
+    // encryption & decryption
+    CKMC_PARAM_ED_IV = 101,         /**< 16B buffer (up to 2^64-1 bytes long in case of AES GCM) */
+    CKMC_PARAM_ED_CTR_LEN,          /**< integer - ctr length in bits*/
+    CKMC_PARAM_ED_AAD,              /**< buffer */
+    CKMC_PARAM_ED_TAG_LEN,          /**< integer - tag length in bits */
+    CKMC_PARAM_ED_LABEL,            /**< buffer */
+
+    // key generation
+    CKMC_PARAM_GEN_KEY_LEN = 201,   /**< integer - key length in bits */
+    CKMC_PARAM_GEN_EC,              /**< integer - elliptic curve (ckmc_ec_type_e) */
+
+    // sign & verify
+    CKMC_PARAM_SV_HASH_ALGO = 301,  /**< integer - hash algorithm (ckmc_hash_algo_e) */
+    CKMC_PARAM_SV_RSA_PADDING,      /**< integer - RSA padding (ckmc_rsa_padding_algo_e) */
+}ckmc_param_name_e;
+
+/**
+ * @brief Structure for algorithm parameter list.
+ * @since_tizen 3.0
+ */
+typedef struct __ckmc_param_list ckmc_param_list_s;
+
+/**
+ * @brief Enumeration for crypto algorithm types.
+ * @since_tizen 3.0
+ */
+typedef enum __ckmc_algo_type {
+    CKMC_ALGO_AES_CTR = 1,   /**< AES-CTR algorithm
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_ED_IV
+                                  - CKMC_PARAM_ED_CTR_LEN (128 only) */
+
+    CKMC_ALGO_AES_CBC,       /**< AES-CBC algorithm
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_ED_IV */
+
+    CKMC_ALGO_AES_GCM,       /**< AES-GCM algorithm
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_ED_IV
+                                  - CKMC_PARAM_ED_TAG_LEN
+                                  - CKMC_PARAM_ED_AAD */
+
+    CKMC_ALGO_AES_CFB,       /**< AES-CFB algorithm
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_ED_IV */
+
+    CKMC_ALGO_RSA_OAEP,      /**< RSA-OAEP algorithm
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_ED_LABEL */
+
+    CKMC_ALGO_RSA_SV,        /**< RSA algorithm used for signing/verification
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_SV_HASH_ALGO
+                                  - CKMC_PARAM_SV_RSA_PADDING */
+
+    CKMC_ALGO_DSA_SV,        /**< DSA algorithm used for signing/verification
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_SV_HASH_ALGO */
+
+    CKMC_ALGO_ECDSA_SV,      /**< ECDA algorithm used for signing/verification
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_SV_HASH_ALGO */
+
+    CKMC_ALGO_RSA_GEN,       /**< RSA algorithm used for key generation
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_GEN_KEY_LEN */
+
+    CKMC_ALGO_DSA_GEN,       /**< DSA algorithm used for key generation
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_GEN_KEY_LEN */
+
+    CKMC_ALGO_ECDSA_GEN,     /**< ECDSA algorithm used for key generation
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_GEN_EC */
+
+    CKMC_ALGO_AES_GEN,       /**< AES key generation
+                                  Supported parameters:
+                                  - CKMC_PARAM_ALGO_TYPE,
+                                  - CKMC_PARAM_GEN_KEY_LEN */
+} ckmc_algo_type_e;
 
 /**
  * @internal
@@ -634,6 +742,202 @@ void ckmc_cert_list_free(ckmc_cert_list_s *first);
 void ckmc_cert_list_all_free(ckmc_cert_list_s *first);
 
 /**
+ * @brief Creates new parameter list
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks Caller is responsible for freeing it with ckmc_param_list_free
+ *
+ * @param[in] ppparam_list  Double pointer to the list variable to which the newly created list will
+ *                          be assigned.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ *
+ * @retval #CKMC_ERROR_NONE                 Successful
+ * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
+ *
+ * @see ckmc_param_list_add_integer
+ * @see ckmc_param_list_add_buffer
+ * @see ckmc_param_list_free
+ * @see ckmc_generate_params
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+int ckmc_param_list_new(ckmc_param_list_s **ppparams);
+
+/**
+ * @brief Adds integer parameter to the list
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks Caller is responsible for ckmc_param_list_s creation.
+ *
+ * @param[in] params    List of params created with ckcm_param_list_new.
+ * @param[in] name      Name of parameter to add. Existing parameter will be overwritten. Passing
+ *                      invalid parameter name will result in an error.
+ * @param[in] value     Value of the parameter in form of a integer.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ *
+ * @retval #CKMC_ERROR_NONE                 Successful
+ * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
+ *
+ * @see ckmc_param_list_new
+ * @see ckmc_param_list_add_buffer
+ * @see ckmc_param_list_get_integer
+ * @see ckmc_param_list_get_buffer
+ * @see ckmc_param_list_free
+ * @see ckmc_generate_params
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+int ckmc_param_list_add_integer(ckmc_param_list_s *params,
+                                ckmc_param_name_e name,
+                                uint64_t value);
+
+/**
+ * @brief Adds buffer parameter to the list
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks Caller is responsible for ckmc_param_list_s creation.
+ *
+ * @param[in] params    List of params created with ckcm_param_list_new.
+ * @param[in] name      Name of parameter to add. Existing parameter will be overwritten. Passing
+ *                      invalid parameter name will result in an error
+ * @param[in] buffer    Value of the parameter in form of a buffer. Caller is responsible for
+ *                      creating and freeing the buffer.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ *
+ * @retval #CKMC_ERROR_NONE                 Successful
+ * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
+ *
+ * @see ckmc_param_list_new
+ * @see ckmc_param_list_add_integer
+ * @see ckmc_param_list_get_integer
+ * @see ckmc_param_list_get_buffer
+ * @see ckmc_param_list_free
+ * @see ckmc_generate_params
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+int ckmc_param_list_add_buffer(ckmc_param_list_s *params,
+                               ckmc_param_name_e name,
+                               const ckmc_raw_buffer_s *buffer);
+
+/**
+ * @brief Gets integer parameter from the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks Caller is responsible for ckmc_param_list_s creation.
+ *
+ * @param[in] params    List of params created with ckcm_param_list_new.
+ * @param[in] name      Name of parameter to get.
+ * @param[out] value    Value of the parameter in form of a integer.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ *
+ * @retval #CKMC_ERROR_NONE                 Successful
+ * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
+ *
+ * @see ckmc_param_list_new
+ * @see ckmc_param_list_add_integer
+ * @see ckmc_param_list_add_buffer
+ * @see ckmc_param_list_get_buffer
+ * @see ckmc_param_list_free
+ * @see ckmc_generate_params
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+
+int ckmc_param_list_get_integer(const ckmc_param_list_s *params,
+                                ckmc_param_name_e name,
+                                uint64_t* value);
+
+/**
+ * @brief Gets buffer parameter from the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks Caller is responsible for ckmc_param_list_s creation.
+ *
+ * @param[in] params    List of params created with ckcm_param_list_new.
+ * @param[in] name      Name of parameter to get.
+ * @param[out] buffer   Value of the parameter in form of a buffer. Caller is responsible for
+ *                      creating and freeing the buffer.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ *
+ * @retval #CKMC_ERROR_NONE                 Successful
+ * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
+ *
+ * @see ckmc_param_list_new
+ * @see ckmc_param_list_add_integer
+ * @see ckmc_param_list_add_buffer
+ * @see ckmc_param_list_get_integer
+ * @see ckmc_param_list_free
+ * @see ckmc_generate_params
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+int ckmc_param_list_get_buffer(const ckmc_param_list_s *params,
+                               ckmc_param_name_e name,
+                               ckmc_raw_buffer_s **buffer);
+
+/**
+ * @brief Frees previously allocated list of algorithm params
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] first     First element of the list to be freed.
+ *
+ * @see ckmc_param_list_new
+ * @see ckmc_param_list_add_integer
+ * @see ckmc_param_list_add_buffer
+ * @see ckmc_param_list_get_integer
+ * @see ckmc_param_list_get_buffer
+ * @see ckmc_generate_params
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+
+void ckmc_param_list_free(ckmc_param_list_s *params);
+
+/**
+ * @brief Generates algorithm parameters for a given algorithm type and adds them to the list.
+ *
+ * @since_tizen 3.0
+ *
+ * @remarks Caller is responsible for ckmc_param_list_s creation and destruction.
+ * @remarks Algorithm parameters are set to default values. Optional fields are left empty.
+ *          Initialization vectors are left empty (they have to be added manually). Existing params
+ *          will be overwritten with default values. Caller is responsible for freeing the list with
+ *          ckmc_param_list_free.
+ * @remarks If the function returns error provided param list may contain some of default parameters
+ *
+ * @param[in] type      Type of the algorithm
+ * @param[out] params   List of params to be filled. List should be empty. Otherwise an error will
+ *                      be returned.
+ *
+ * @return @c 0 on success, otherwise a negative error value
+ *
+ * @retval #CKMC_ERROR_NONE                 Successful
+ * @retval #CKMC_ERROR_INVALID_PARAMETER    Input parameter is invalid
+ *
+ * @see ckmc_param_list_new
+ * @see ckmc_param_list_add_integer
+ * @see ckmc_param_list_add_buffer
+ * @see ckmc_param_list_get_integer
+ * @see ckmc_param_list_get_buffer
+ * @see ckmc_param_list_free
+ * @see #ckmc_param_list_s
+ * @see #ckmc_param_name_e
+ */
+int ckmc_generate_params(ckmc_algo_type_e type, ckmc_param_list_s *params);
+
+/**
  * @}
  */