ACR: Consistency for the get_output_length() function 40/73340/3
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Tue, 7 Jun 2016 15:39:53 +0000 (17:39 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Wed, 8 Jun 2016 10:11:51 +0000 (12:11 +0200)
Removed the macros, get_output_length function renamed to include
"context". Documentation updated.

Change-Id: I6f8857b25e43dfb80a258bdb857097a79e443889

12 files changed:
api/yaca/yaca_crypto.h
api/yaca/yaca_digest.h
api/yaca/yaca_encrypt.h
api/yaca/yaca_seal.h
api/yaca/yaca_sign.h
examples/digest.c
examples/encrypt.c
examples/encrypt_aes_gcm_ccm.c
examples/seal.c
examples/sign.c
src/crypto.c
src/simple.c

index 3964d7e..badc635 100644 (file)
@@ -256,6 +256,10 @@ int yaca_context_destroy(yaca_context_h ctx);
  *
  * @since_tizen 3.0
  *
+ * @remarks  This function can be used to learn the required size of the output buffer
+ *           for a single operation (eg. *_update or *_finalize). In case the operation
+ *           has no input (eg. *_finalize), the value of @b input_len should be set to 0.
+ *
  * @param[in]  ctx         Previously initialized crypto context
  * @param[in]  input_len   Length of the input data to be processed
  * @param[out] output_len  Required length of the output
@@ -263,31 +267,10 @@ int yaca_context_destroy(yaca_context_h ctx);
  * @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,
- *                                       invalid context or input_len)
+ *                                       invalid context or too big input_len)
  * @retval #YACA_ERROR_INTERNAL Internal error
  */
-int yaca_get_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len);
-
-/**
- * @brief  Wrapper - returns the length of the digest (for a given context).
- *
- * @since_tizen 3.0
- */
-#define yaca_get_digest_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
-
-/**
- * @brief  Wrapper - returns the length of the signature (for a given context).
- *
- * @since_tizen 3.0
- */
-#define yaca_get_sign_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
-
-/**
- * @brief  Wrapper - returns the length of the block (for a given context).
- *
- * @since_tizen 3.0
- */
-#define yaca_get_block_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
+int yaca_context_get_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len);
 
 /**@}*/
 
index 8ad20d8..4c72af5 100644 (file)
@@ -88,7 +88,7 @@ int yaca_digest_update(yaca_context_h ctx, const char *data, size_t data_len);
  *
  * @param[in,out] ctx         A valid digest context
  * @param[out]    digest      Buffer for the message digest
- *                            (must be allocated by client, see yaca_get_digest_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    digest_len  Length of the digest,
  *                            actual number of bytes written will be returned here
  *
@@ -100,7 +100,7 @@ int yaca_digest_update(yaca_context_h ctx, const char *data, size_t data_len);
  *
  * @see yaca_digest_initialize()
  * @see yaca_digest_update()
- * @see yaca_get_digest_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_digest_finalize(yaca_context_h ctx, char *digest, size_t *digest_len);
 
index 062caa7..f0e6ee2 100644 (file)
@@ -78,7 +78,7 @@ int yaca_encrypt_initialize(yaca_context_h *ctx,
  * @param[in]     plain       Plain text to be encrypted
  * @param[in]     plain_len   Length of the plain text
  * @param[out]    cipher      Buffer for the encrypted data
- *                            (must be allocated by client, see yaca_get_output_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    cipher_len  Length of the encrypted data,
  *                            actual number of bytes written will be returned here
  *
@@ -90,7 +90,7 @@ int yaca_encrypt_initialize(yaca_context_h *ctx,
  *
  * @see yaca_encrypt_initialize()
  * @see yaca_encrypt_finalize()
- * @see yaca_get_output_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_encrypt_update(yaca_context_h ctx,
                         const char *plain,
@@ -105,7 +105,7 @@ int yaca_encrypt_update(yaca_context_h ctx,
  *
  * @param[in,out] ctx         A valid encrypt context
  * @param[out]    cipher      Final piece of the encrypted data
- *                            (must be allocated by client, see yaca_get_block_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    cipher_len  Length of the final piece,
  *                            actual number of bytes written will be returned here
  *
@@ -117,7 +117,7 @@ int yaca_encrypt_update(yaca_context_h ctx,
  *
  * @see yaca_encrypt_initialize()
  * @see yaca_encrypt_update()
- * @see yaca_get_output_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_encrypt_finalize(yaca_context_h ctx,
                           char *cipher,
@@ -162,7 +162,7 @@ int yaca_decrypt_initialize(yaca_context_h *ctx,
  * @param[in]     cipher      Cipher text to be decrypted
  * @param[in]     cipher_len  Length of the cipher text
  * @param[out]    plain       Buffer for the decrypted data
- *                            (must be allocated by client, see yaca_get_output_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    plain_len   Length of the decrypted data,
  *                            actual number of bytes written will be returned here
  *
@@ -174,7 +174,7 @@ int yaca_decrypt_initialize(yaca_context_h *ctx,
  *
  * @see yaca_decrypt_initialize()
  * @see yaca_decrypt_finalize()
- * @see yaca_get_output_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_decrypt_update(yaca_context_h ctx,
                         const char *cipher,
@@ -189,7 +189,7 @@ int yaca_decrypt_update(yaca_context_h ctx,
  *
  * @param[in,out] ctx        A valid decrypt context
  * @param[out]    plain      Final piece of the decrypted data
- *                           (must be allocated by client, see yaca_get_block_length())
+ *                           (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    plain_len  Length of the final piece,
  *                           actual number of bytes written will be returned here
  *
@@ -201,7 +201,7 @@ int yaca_decrypt_update(yaca_context_h ctx,
  *
  * @see yaca_decrypt_initialize()
  * @see yaca_decrypt_update()
- * @see yaca_get_block_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_decrypt_finalize(yaca_context_h ctx,
                           char *plain,
index 58b4102..f1e351b 100644 (file)
@@ -90,7 +90,7 @@ int yaca_seal_initialize(yaca_context_h *ctx,
  * @param[in]     plain       Plain text to be encrypted
  * @param[in]     plain_len   Length of the plain text
  * @param[out]    cipher      Buffer for the encrypted data
- *                            (must be allocated by client, see yaca_get_output_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    cipher_len  Length of the encrypted data,
  *                            actual number of bytes written will be returned here
  *
@@ -102,7 +102,7 @@ int yaca_seal_initialize(yaca_context_h *ctx,
  *
  * @see yaca_seal_initialize()
  * @see yaca_seal_finalize()
- * @see yaca_get_output_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_seal_update(yaca_context_h ctx,
                      const char *plain,
@@ -117,7 +117,7 @@ int yaca_seal_update(yaca_context_h ctx,
  *
  * @param[in,out] ctx         A valid seal context
  * @param[out]    cipher      Final piece of the encrypted data
- *                            (must be allocated by client, see yaca_get_block_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    cipher_len  Length of the final piece,
  *                            actual number of bytes written will be returned here
  *
@@ -129,7 +129,7 @@ int yaca_seal_update(yaca_context_h ctx,
  *
  * @see yaca_seal_initialize()
  * @see yaca_seal_update()
- * @see yaca_get_block_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_seal_finalize(yaca_context_h ctx,
                        char *cipher,
@@ -179,7 +179,7 @@ int yaca_open_initialize(yaca_context_h *ctx,
  * @param[in]     cipher      Cipher text to be decrypted
  * @param[in]     cipher_len  Length of the cipher text
  * @param[out]    plain       Buffer for the decrypted data
- *                            (must be allocated by client, see yaca_get_output_length())
+ *                            (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    plain_len   Length of the decrypted data,
  *                            actual number of bytes written will be returned here
  *
@@ -191,7 +191,7 @@ int yaca_open_initialize(yaca_context_h *ctx,
  *
  * @see yaca_open_initialize()
  * @see yaca_open_finalize()
- * @see yaca_get_output_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_open_update(yaca_context_h ctx,
                      const char *cipher,
@@ -206,7 +206,7 @@ int yaca_open_update(yaca_context_h ctx,
  *
  * @param[in,out] ctx        A valid open context
  * @param[out]    plain      Final piece of the decrypted data
- *                           (must be allocated by client, see yaca_get_block_length())
+ *                           (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    plain_len  Length of the final piece,
  *                           actual number of bytes written will be returned here
  *
@@ -218,7 +218,7 @@ int yaca_open_update(yaca_context_h ctx,
  *
  * @see yaca_open_initialize()
  * @see yaca_open_update()
- * @see yaca_get_block_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_open_finalize(yaca_context_h ctx,
                        char *plain,
index 4b9ec91..1b91fd0 100644 (file)
@@ -171,7 +171,7 @@ int yaca_sign_update(yaca_context_h ctx,
  *
  * @param[in,out] ctx              A valid sign context
  * @param[out]    signature        Buffer for the MAC or the signature
- *                                 (must be allocated by client, see yaca_get_sign_length())
+ *                                 (must be allocated by client, see yaca_context_get_output_length())
  * @param[out]    signature_len    Length of the MAC or the signature,
  *                                 actual number of bytes written will be returned here
  *
@@ -185,7 +185,7 @@ int yaca_sign_update(yaca_context_h ctx,
  * @see yaca_sign_update()
  * @see yaca_sign_initialize_hmac()
  * @see yaca_sign_initialize_cmac()
- * @see yaca_get_sign_length()
+ * @see yaca_context_get_output_length()
  */
 int yaca_sign_finalize(yaca_context_h ctx,
                        char *signature,
index 78ff483..bbbccb0 100644 (file)
@@ -61,7 +61,7 @@ void digest_advanced(void)
                goto exit;
 
        size_t digest_len;
-       ret = yaca_get_digest_length(ctx, &digest_len);
+       ret = yaca_context_get_output_length(ctx, 0, &digest_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
index ff986cc..426c391 100644 (file)
@@ -113,10 +113,12 @@ void encrypt_advanced(const yaca_encrypt_algorithm_e algo,
                if (yaca_encrypt_initialize(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
@@ -145,10 +147,12 @@ void encrypt_advanced(const yaca_encrypt_algorithm_e algo,
                if (yaca_decrypt_initialize(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
index b0029af..d635ded 100644 (file)
@@ -88,10 +88,12 @@ void encrypt_decrypt_aes_gcm(void)
                if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
@@ -132,10 +134,12 @@ void encrypt_decrypt_aes_gcm(void)
                if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
@@ -236,10 +240,12 @@ void encrypt_decrypt_aes_ccm(void)
                if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
@@ -283,10 +289,12 @@ void encrypt_decrypt_aes_ccm(void)
                if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
index c9570e2..11e40fc 100644 (file)
@@ -67,10 +67,12 @@ void encrypt_seal(void)
                if (yaca_seal_initialize(&ctx, key_pub, algo, bcm, key_bits, &aes_key, &iv) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
@@ -100,10 +102,12 @@ void encrypt_seal(void)
                if (yaca_open_initialize(&ctx, key_priv, algo, bcm, key_bits, aes_key, iv) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE)
+               /* For the update */
+               if (yaca_context_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
                        goto exit;
 
-               if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE)
+               /* For the finalize */
+               if (yaca_context_get_output_length(ctx, 0, &block_len) != YACA_ERROR_NONE)
                        goto exit;
 
                /* Calculate max output: size of update + final chunks */
index fa5eac5..60057b4 100644 (file)
@@ -192,7 +192,7 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo)
        if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
+       if (yaca_context_get_output_length(ctx, 0, &signature_len) != YACA_ERROR_NONE)
                goto exit;
 
        if (yaca_malloc(signature_len, (void**)&signature) != YACA_ERROR_NONE)
@@ -249,7 +249,7 @@ void sign_verify_hmac(void)
        if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
+       if (yaca_context_get_output_length(ctx, 0, &signature_len) != YACA_ERROR_NONE)
                goto exit;
 
        if (yaca_malloc(signature_len, (void**)&signature1) != YACA_ERROR_NONE)
@@ -271,7 +271,7 @@ void sign_verify_hmac(void)
        if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
                goto exit;
 
-       if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
+       if (yaca_context_get_output_length(ctx, 0, &signature_len) != YACA_ERROR_NONE)
                goto exit;
 
        if (yaca_malloc(signature_len, (void**)&signature2) != YACA_ERROR_NONE)
@@ -312,7 +312,7 @@ void sign_verify_cmac(void)
        if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE))
                goto exit;
 
-       if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
+       if (yaca_context_get_output_length(ctx, 0, &signature_len) != YACA_ERROR_NONE)
                goto exit;
 
        if (yaca_malloc(signature_len, (void**)&signature1) != YACA_ERROR_NONE)
@@ -334,7 +334,7 @@ void sign_verify_cmac(void)
        if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE))
                goto exit;
 
-       if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE)
+       if (yaca_context_get_output_length(ctx, 0, &signature_len) != YACA_ERROR_NONE)
                goto exit;
 
        if (yaca_malloc(signature_len, (void**)&signature2) != YACA_ERROR_NONE)
index 8b4c174..0d4055a 100644 (file)
@@ -244,7 +244,7 @@ API int yaca_context_destroy(yaca_context_h ctx)
        return YACA_ERROR_NONE;
 }
 
-API int yaca_get_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len)
+API int yaca_context_get_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len)
 {
        if (ctx == YACA_CONTEXT_NULL)
                return YACA_ERROR_INVALID_PARAMETER;
index 19c0f1a..d5e3cae 100644 (file)
@@ -55,7 +55,7 @@ API int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       ret = yaca_get_digest_length(ctx, &ldigest_len);
+       ret = yaca_context_get_output_length(ctx, 0, &ldigest_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
@@ -102,11 +102,11 @@ API int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       ret = yaca_get_block_length(ctx, &lcipher_len);
+       ret = yaca_context_get_output_length(ctx, plain_len, &out_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       ret = yaca_get_output_length(ctx, plain_len, &out_len);
+       ret = yaca_context_get_output_length(ctx, 0, &lcipher_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
@@ -177,11 +177,11 @@ API int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       ret = yaca_get_block_length(ctx, &lplain_len);
+       ret = yaca_context_get_output_length(ctx, cipher_len, &out_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
-       ret = yaca_get_output_length(ctx, cipher_len, &out_len);
+       ret = yaca_context_get_output_length(ctx, 0, &lplain_len);
        if (ret != YACA_ERROR_NONE)
                goto exit;
 
@@ -241,7 +241,7 @@ static int sign(const yaca_context_h ctx, const char *data, size_t data_len,
        if (ret != YACA_ERROR_NONE)
                return ret;
 
-       ret = yaca_get_sign_length(ctx, signature_len);
+       ret = yaca_context_get_output_length(ctx, 0, signature_len);
        if (ret != YACA_ERROR_NONE)
                return ret;