Allow empty input for yaca_simple_caclulate_digest 22/75822/2
authorKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Tue, 21 Jun 2016 14:18:41 +0000 (16:18 +0200)
committerKrzysztof Jackiewicz <k.jackiewicz@samsung.com>
Thu, 23 Jun 2016 08:03:58 +0000 (10:03 +0200)
Change-Id: Ibaed61aec9e5370c4521139629a9ac108a6aa3ca

api/yaca/yaca_simple.h
src/simple.c

index 86f2f88..ecd532a 100644 (file)
@@ -54,13 +54,13 @@ extern "C" {
  *
  * @param[in]  algo        Digest algorithm (select #YACA_DIGEST_SHA256 if unsure)
  * @param[in]  data        Data from which the digest is to be calculated
- * @param[in]  data_len    Length of the data
+ * @param[in]  data_len    Length of the data. Can be 0.
  * @param[out] digest      Message digest, will be allocated by the library
  * @param[out] digest_len  Length of message digest (depends on algorithm)
  *
  * @return #YACA_ERROR_NONE on success, negative on error
  * @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
  *                                       invalid algo)
  * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
  * @retval #YACA_ERROR_INTERNAL Internal error
index a17f78e..a621281 100644 (file)
@@ -44,16 +44,18 @@ API int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
        char *ldigest = NULL;
        size_t ldigest_len;
 
-       if (data == NULL || data_len == 0 || digest == NULL || digest_len == NULL)
+       if ((data == NULL && data_len > 0) || digest == NULL || digest_len == NULL)
                return YACA_ERROR_INVALID_PARAMETER;
 
        ret = yaca_digest_initialize(&ctx, algo);
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       ret = yaca_digest_update(ctx, data, data_len);
-       if (ret != YACA_ERROR_NONE)
-               goto exit;
+       if (data_len > 0) {
+               ret = yaca_digest_update(ctx, data, data_len);
+               if (ret != YACA_ERROR_NONE)
+                       goto exit;
+       }
 
        ret = yaca_context_get_output_length(ctx, 0, &ldigest_len);
        if (ret != YACA_ERROR_NONE)