*
* @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
* @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);
/**@}*/
*
* @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
*
*
* @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);
* @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
*
*
* @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,
*
* @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
*
*
* @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,
* @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
*
*
* @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,
*
* @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
*
*
* @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,
* @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
*
*
* @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,
*
* @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
*
*
* @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,
* @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
*
*
* @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,
*
* @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
*
*
* @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,
*
* @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
*
* @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,
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;
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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 */
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)
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)
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)
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)
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)
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;
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;
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;
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;
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;