From f38dab94e6bcf01d7e1ed35608fac813e9f66606 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Thu, 30 Jun 2016 15:10:17 +0200 Subject: [PATCH] Allow NULL value_len in yaca_context_get_property(). Fix documentation. In cases where a property is a single object of a known type theres no point in passing value_len to yaca_context_get_property(). The documentation related to property getting/setting has been updated. Change-Id: Idf908e87b87b5fe5239f651fe8546a7bd5a89850 --- api/yaca/yaca_crypto.h | 8 ++++++++ api/yaca/yaca_types.h | 16 +++++++++------- src/encrypt.c | 6 +++--- src/sign.c | 5 +++-- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/api/yaca/yaca_crypto.h b/api/yaca/yaca_crypto.h index baf0315..20cae17 100644 --- a/api/yaca/yaca_crypto.h +++ b/api/yaca/yaca_crypto.h @@ -190,6 +190,9 @@ int yaca_randomize_bytes(char *data, size_t data_len); * @brief Sets the non-standard context properties. Can only be called on an * initialized context. * + * @remarks The @a value has to be of type appropriate for given property. See #yaca_property_e + * for details on corresponding types. + * * @since_tizen 3.0 * * @param[in,out] ctx Previously initialized crypto context @@ -219,6 +222,11 @@ int yaca_context_set_property(yaca_context_h ctx, * * @remarks The @a value should be freed using yaca_free() * + * @remarks The @a value has to be of type appropriate for given property. See #yaca_property_e + * for details on corresponding types. + * + * @remarks @a value_len can be NULL if returned @a value is a single object (i.e. not an array/buffer) + * * @param[in] ctx Previously initialized crypto context * @param[in] property Property to be read * @param[out] value Copy of the property value diff --git a/api/yaca/yaca_types.h b/api/yaca/yaca_types.h index 2d5edc9..4508c8d 100644 --- a/api/yaca/yaca_types.h +++ b/api/yaca/yaca_types.h @@ -385,23 +385,25 @@ typedef enum { * @brief Enumeration of YACA non-standard properties for algorithms. * * @since_tizen 3.0 + * + * @see #yaca_padding_e */ typedef enum { - /** Padding */ + /** Padding. Property type is #yaca_padding_e. */ YACA_PROPERTY_PADDING, - /** GCM Additional Authentication Data */ + /** GCM Additional Authentication Data. Property type is a buffer (e.g. char*) */ YACA_PROPERTY_GCM_AAD, - /** GCM Tag bits */ + /** GCM Tag. Property type is a buffer (e.g. char*) */ YACA_PROPERTY_GCM_TAG, - /** GCM Tag length */ + /** GCM Tag length. Property type is size_t. */ YACA_PROPERTY_GCM_TAG_LEN, - /** CCM Additional Authentication Data */ + /** CCM Additional Authentication Data. Property type is a buffer (e.g. char*) */ YACA_PROPERTY_CCM_AAD, - /** CCM Tag bits */ + /** CCM Tag. Property type is a buffer (e.g. char*) */ YACA_PROPERTY_CCM_TAG, - /** CCM Tag length */ + /** CCM Tag length. Property type is size_t. */ YACA_PROPERTY_CCM_TAG_LEN } yaca_property_e; diff --git a/src/encrypt.c b/src/encrypt.c index 5942e2e..b248896 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -168,13 +168,13 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property, { struct yaca_encrypt_context_s *c = get_encrypt_context(ctx); - if (c == NULL || value == NULL || value_len == NULL) + if (c == NULL || value == NULL) return YACA_ERROR_INVALID_PARAMETER; assert(c->cipher_ctx != NULL); switch (property) { case YACA_PROPERTY_GCM_TAG: - if (c->tag_len == 0) + if (c->tag_len == 0 || value_len == 0) return YACA_ERROR_INVALID_PARAMETER; if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx, @@ -186,7 +186,7 @@ int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property, *value_len = c->tag_len; break; case YACA_PROPERTY_CCM_TAG: - if (c->tag_len == 0) + if (c->tag_len == 0 || value_len == 0) return YACA_ERROR_INVALID_PARAMETER; if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx, diff --git a/src/sign.c b/src/sign.c index 5dd261c..acb0392 100644 --- a/src/sign.c +++ b/src/sign.c @@ -179,7 +179,7 @@ int get_sign_param(const yaca_context_h ctx, int pad; yaca_padding_e padding; - if (c == NULL || value == NULL || value_len == NULL) + if (c == NULL || value == NULL) return YACA_ERROR_INVALID_PARAMETER; assert(c->mdctx != NULL); @@ -230,7 +230,8 @@ int get_sign_param(const yaca_context_h ctx, return ret; memcpy(*value, &padding, sizeof(yaca_padding_e)); - *value_len = sizeof(yaca_padding_e); + if (value_len != NULL) + *value_len = sizeof(yaca_padding_e); return YACA_ERROR_NONE; } -- 2.7.4