*
* @since_tizen 3.0
*/
-#define YACA_CTX_NULL ((yaca_ctx_h) NULL)
+#define YACA_CONTEXT_NULL ((yaca_context_h) NULL)
/**
* @brief Initializes the library. Must be called before any other crypto function.
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_exit()
+ * @see yaca_cleanup()
*/
-int yaca_init(void);
+int yaca_initialize(void);
/**
* @brief Closes the library. Must be called before exiting the application.
*
* @since_tizen 3.0
*
- * @see yaca_init()
- *
* @return #YACA_ERROR_NONE on success
* @retval #YACA_ERROR_NONE Successful
+ *
+ * @see yaca_initialize()
*/
-int yaca_exit(void);
+int yaca_cleanup(void);
/**
* @brief Allocates the memory.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
*
* @see yaca_zalloc()
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
*
* @see yaca_malloc()
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
*
* @see yaca_malloc()
int yaca_free(void *ptr);
/**
+ * @brief Safely compares first @b len bytes of two buffers.
+ *
+ * @since_tizen 3.0
+ *
+ * @param[in] first Pointer to the first buffer
+ * @param[in] second Pointer to the second buffer
+ * @param[in] len Length to compare
+ *
+ * @return #YACA_ERROR_NONE when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH
+ * @retval #YACA_ERROR_NONE Successful
+ * @retval #YACA_ERROR_DATA_MISMATCH Buffers are different
+ */
+int yaca_memcmp(const void *first, const void *second, size_t len);
+
+/**
* @brief Generates random data.
*
* @since_tizen 3.0
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0)
* @retval #YACA_ERROR_INTERNAL Internal error
*/
-int yaca_rand_bytes(char *data, size_t data_len);
+int yaca_randomize_bytes(char *data, size_t data_len);
/**
- * @brief Sets the extended context parameters. Can only be called on an
+ * @brief Sets the non-standard context properties. Can only be called on an
* initialized context.
*
* @since_tizen 3.0
*
* @param[in,out] ctx Previously initialized crypto context
- * @param[in] param Parameter to be set
- * @param[in] value Parameter value
- * @param[in] value_len Length of the parameter value
+ * @param[in] param Property to be set
+ * @param[in] value Property value
+ * @param[in] value_len Length of the property value
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context or param)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid ctx or param)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_ex_param_e
- * @see yaca_ctx_get_param()
+ * @see #yaca_property_e
+ * @see yaca_context_get_property()
*/
-int yaca_ctx_set_param(yaca_ctx_h ctx,
- yaca_ex_param_e param,
- const void *value,
- size_t value_len);
+int yaca_context_set_property(yaca_context_h ctx,
+ yaca_property_e param,
+ const void *value,
+ size_t value_len);
/**
- * @brief Returns the extended context parameters. Can only be called on an
+ * @brief Returns the non-standard context properties. Can only be called on an
* initialized context.
*
* @since_tizen 3.0
*
* @param[in] ctx Previously initialized crypto context
- * @param[in] param Parameter to be read
- * @param[out] value Copy of the parameter value (must be freed with yaca_free())
- * @param[out] value_len Length of the parameter value will be returned here
+ * @param[in] param Property to be read
+ * @param[out] value Copy of the property value (must be freed with yaca_free())
+ * @param[out] value_len Length of the property value will be returned here
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context or param)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid ctx or param)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_ex_param_e
- * @see yaca_ctx_set_param()
+ * @see #yaca_property_e
+ * @see yaca_context_set_property()
* @see yaca_free()
*/
-int yaca_ctx_get_param(const yaca_ctx_h ctx,
- yaca_ex_param_e param,
- void **value,
- size_t *value_len);
+int yaca_context_get_property(const yaca_context_h ctx,
+ yaca_property_e param,
+ void **value,
+ size_t *value_len);
/**
* @brief Destroys the crypto context. Must be called on all contexts that are
- * no longer used. Passing #YACA_CTX_NULL is allowed.
+ * no longer used. Passing #YACA_CONTEXT_NULL is allowed.
*
* @since_tizen 3.0
*
* @return #YACA_ERROR_NONE on success
* @retval #YACA_ERROR_NONE Successful
*
- * @see #yaca_ctx_h
+ * @see #yaca_context_h
*
*/
-int yaca_ctx_free(yaca_ctx_h ctx);
+int yaca_context_destroy(yaca_context_h ctx);
/**
* @brief Returns the output length for a given algorithm. Can only be called
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context or input_len)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context or input_len)
* @retval #YACA_ERROR_INTERNAL Internal error
*/
-int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len);
+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).
*/
#define yaca_get_block_length(ctxa, output_len) yaca_get_output_length((ctxa), 0, (output_len))
-/**
- * @brief Safely compares first @b len bytes of two buffers.
- *
- * @since_tizen 3.0
- *
- * @param[in] first Pointer to the first buffer
- * @param[in] second Pointer to the second buffer
- * @param[in] len Length to compare
- *
- * @return #YACA_ERROR_NONE when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH
- * @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_DATA_MISMATCH Buffers are different
- */
-int yaca_memcmp(const void *first, const void *second, size_t len);
-
/**@}*/
#ifdef __cplusplus
*
* @since_tizen 3.0
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Digest algorithm that will be used
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo)
+ * @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
*
- * @see #yaca_digest_algo_e
+ * @see #yaca_digest_algorithm_e
* @see yaca_digest_update()
- * @see yaca_digest_final()
- * @see yaca_ctx_free()
+ * @see yaca_digest_finalize()
+ * @see yaca_context_destroy()
*/
-int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo);
+int yaca_digest_initialize(yaca_context_h *ctx, yaca_digest_algorithm_e algo);
/**
* @brief Feeds the data into the message digest algorithm.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_digest_init()
+ * @param[in,out] ctx Context created by yaca_digest_initialize()
* @param[in] data Data from which the digest is to be calculated
* @param[in] data_len Length of the data
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_digest_init()
- * @see yaca_digest_final()
+ * @see yaca_digest_initialize()
+ * @see yaca_digest_finalize()
*/
-int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len);
+int yaca_digest_update(yaca_context_h ctx, const char *data, size_t data_len);
/**
* @brief Calculates the final digest.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_digest_init()
+ * @see yaca_digest_initialize()
* @see yaca_digest_update()
* @see yaca_get_digest_length()
*/
-int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len);
+int yaca_digest_finalize(yaca_context_h ctx, char *digest, size_t *digest_len);
/**@}*/
*
* @since_tizen 3.0
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Encryption algorithm that will be used
* @param[in] bcm Chaining mode that will be used
* @param[in] sym_key Symmetric key that will be used
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo, bcm, sym_key or iv)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo, bcm, sym_key or iv)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see #yaca_block_cipher_mode_e
* @see yaca_encrypt_update()
- * @see yaca_encrypt_final()
- * @see yaca_ctx_free()
+ * @see yaca_encrypt_finalize()
+ * @see yaca_context_destroy()
*/
-int yaca_encrypt_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv);
+int yaca_encrypt_initialize(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
* @brief Encrypts chunk of the data.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_encrypt_init()
+ * @param[in,out] ctx Context created by yaca_encrypt_initialize()
* @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
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_encrypt_init()
- * @see yaca_encrypt_final()
+ * @see yaca_encrypt_initialize()
+ * @see yaca_encrypt_finalize()
* @see yaca_get_output_length()
*/
-int yaca_encrypt_update(yaca_ctx_h ctx,
+int yaca_encrypt_update(yaca_context_h ctx,
const char *plain,
size_t plain_len,
char *cipher,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_encrypt_init()
+ * @see yaca_encrypt_initialize()
* @see yaca_encrypt_update()
* @see yaca_get_output_length()
*/
-int yaca_encrypt_final(yaca_ctx_h ctx,
- char *cipher,
- size_t *cipher_len);
+int yaca_encrypt_finalize(yaca_context_h ctx,
+ char *cipher,
+ size_t *cipher_len);
/**
* @brief Initializes an decryption context.
*
* @since_tizen 3.0
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Encryption algorithm that was used to encrypt the data
* @param[in] bcm Chaining mode that was used to encrypt the data
* @param[in] sym_key Symmetric key that was used to encrypt the data
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo, bcm, sym_key or iv)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo, bcm, sym_key or iv)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see #yaca_block_cipher_mode_e
* @see yaca_decrypt_update()
- * @see yaca_decrypt_final()
- * @see yaca_ctx_free()
+ * @see yaca_decrypt_finalize()
+ * @see yaca_context_destroy()
*/
-int yaca_decrypt_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv);
+int yaca_decrypt_initialize(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
* @brief Decrypts chunk of the data.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_decrypt_init()
+ * @param[in,out] ctx Context created by yaca_decrypt_initialize()
* @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
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_decrypt_init()
- * @see yaca_decrypt_final()
+ * @see yaca_decrypt_initialize()
+ * @see yaca_decrypt_finalize()
* @see yaca_get_output_length()
*/
-int yaca_decrypt_update(yaca_ctx_h ctx,
+int yaca_decrypt_update(yaca_context_h ctx,
const char *cipher,
size_t cipher_len,
char *plain,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_decrypt_init()
+ * @see yaca_decrypt_initialize()
* @see yaca_decrypt_update()
* @see yaca_get_block_length()
*/
-int yaca_decrypt_final(yaca_ctx_h ctx,
- char *plain,
- size_t *plain_len);
+int yaca_decrypt_finalize(yaca_context_h ctx,
+ char *plain,
+ size_t *plain_len);
/**
* @brief Returns the recommended/default length of the IV for a given encryption configuration.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo, bcm or key_bits)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo, bcm or key_bits)
* @retval #YACA_ERROR_INTERNAL Internal error
*
*/
-int yaca_get_iv_bits(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bits,
- size_t *iv_bits);
+int yaca_encrypt_get_iv_bit_length(yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bits,
+ size_t *iv_bits);
/**@}*/
/** Successful */
YACA_ERROR_NONE = TIZEN_ERROR_NONE,
/** Invalid function parameter */
- YACA_ERROR_INVALID_ARGUMENT = TIZEN_ERROR_INVALID_PARAMETER,
+ YACA_ERROR_INVALID_PARAMETER = TIZEN_ERROR_INVALID_PARAMETER,
/** Out of memory */
YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY,
/** Data mismatch */
YACA_ERROR_DATA_MISMATCH = TIZEN_ERROR_YACA | 0x02,
/** Invalid password */
- YACA_ERROR_PASSWORD_INVALID = TIZEN_ERROR_YACA | 0x03
+ YACA_ERROR_INVALID_PASSWORD = TIZEN_ERROR_YACA | 0x03
} yaca_error_e;
/**@}*/
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Either of the params is NULL
+ * @retval #YACA_ERROR_INVALID_PARAMETER Either of the params is NULL
*/
int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type);
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Either of the params is NULL
+ * @retval #YACA_ERROR_INVALID_PARAMETER Either of the params is NULL
* @retval #YACA_ERROR_INTERNAL Internal error
*/
-int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits);
+int yaca_key_get_bit_length(const yaca_key_h key, size_t *key_bits);
/**
* @brief Imports a key.
*
* @remarks If the key is encrypted the algorithm will be autodetected and password
* used. If it's not known if the key is encrypted one should pass NULL as
- * password and check for the #YACA_ERROR_PASSWORD_INVALID return code.
+ * password and check for the #YACA_ERROR_INVALID_PASSWORD return code.
*
* @param[in] key_type Type of the key
* @param[in] password null terminated password for the key (can be NULL)
* @param[in] data Blob containing the key
* @param[in] data_len Size of the blob
- * @param[out] key Returned key (must be freed with yaca_key_free())
+ * @param[out] key Returned key (must be freed with yaca_key_destroy())
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid key_type or data_len too big)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid key_type or data_len too big)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
- * @retval #YACA_ERROR_PASSWORD_INVALID Invalid password given or password was required
+ * @retval #YACA_ERROR_INVALID_PASSWORD Invalid password given or password was required
* and none was given
*
* @see #yaca_key_type_e
* @see yaca_key_export()
- * @see yaca_key_free()
+ * @see yaca_key_destroy()
*/
int yaca_key_import(yaca_key_type_e key_type,
const char *password,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid key/file format or data_len too big)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid key/file format or data_len too big)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_key_fmt_e
- * @see #yaca_key_file_fmt_e
+ * @see #yaca_key_format_e
+ * @see #yaca_key_file_format_e
* @see yaca_key_import()
- * @see yaca_key_free()
+ * @see yaca_key_destroy()
*/
int yaca_key_export(const yaca_key_h key,
- yaca_key_fmt_e key_fmt,
- yaca_key_file_fmt_e key_file_fmt,
+ yaca_key_format_e key_fmt,
+ yaca_key_file_format_e key_file_fmt,
const char *password,
char **data,
size_t *data_len);
*
* @param[in] key_type Type of the key to be generated
* @param[in] key_bits Length of the key (in bits) to be generated
- * @param[out] key Newly generated key (must be freed with yaca_key_free())
+ * @param[out] key Newly generated key (must be freed with yaca_key_destroy())
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT key is NULL, incorrect key_type or
- * key_bits is not dividable by 8
+ * @retval #YACA_ERROR_INVALID_PARAMETER key is NULL, incorrect key_type or
+ * key_bits is not dividable by 8
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_key_bits_e
- * @see yaca_key_free()
+ * @see #yaca_key_bit_length_e
+ * @see yaca_key_destroy()
*/
-int yaca_key_gen(yaca_key_type_e key_type,
- size_t key_bits,
- yaca_key_h *key);
+int yaca_key_generate(yaca_key_type_e key_type,
+ size_t key_bits,
+ yaca_key_h *key);
/**
* @brief Extracts public key from a private one.
* @since_tizen 3.0
*
* @param[in] prv_key Private key to extract the public one from
- * @param[out] pub_key Extracted public key (must be freed with yaca_key_free())
+ * @param[out] pub_key Extracted public key (must be freed with yaca_key_destroy())
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT prv_key is of invalid type or pub_key is NULL
+ * @retval #YACA_ERROR_INVALID_PARAMETER prv_key is of invalid type or pub_key is NULL
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_key_gen()
+ * @see yaca_key_generate()
* @see yaca_key_import()
- * @see yaca_key_free()
+ * @see yaca_key_destroy()
*/
int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key);
*
* @see yaca_key_import()
* @see yaca_key_export()
- * @see yaca_key_gen()
+ * @see yaca_key_generate()
*/
-int yaca_key_free(yaca_key_h key);
+int yaca_key_destroy(yaca_key_h key);
/**@}*/
* @param[in] iter Number of iterations
* @param[in] algo Digest algorithm that should be used in key generation
* @param[in] key_bits Length of a key (in bits) to be generated
- * @param[out] key Newly generated key (must be freed with yaca_key_free())
+ * @param[out] key Newly generated key (must be freed with yaca_key_destroy())
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid algo or key_bits not dividable by 8)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid algo or key_bits not dividable by 8)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_digest_algo_e
- * @see yaca_key_free()
+ * @see #yaca_digest_algorithm_e
+ * @see yaca_key_destroy()
*/
int yaca_key_derive_pbkdf2(const char *password,
const char *salt,
size_t salt_len,
int iter,
- yaca_digest_algo_e algo,
+ yaca_digest_algorithm_e algo,
size_t key_bits,
yaca_key_h *key);
*
* @since_tizen 3.0
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] pub_key Public key of the peer that will receive the encrypted data
* @param[in] algo Symmetric algorithm that will be used
* @param[in] bcm Block chaining mode for the symmetric algorithm
* @param[in] sym_key_bits Symmetric key length (in bits) that will be generated
* @param[out] sym_key Generated symmetric key that will be used,
* it is encrypted with peer's public key
- * (must be freed with yaca_key_free())
+ * (must be freed with yaca_key_destroy())
* @param[out] iv Generated initialization vector that will be used
- * (must be freed with yaca_key_free())
+ * (must be freed with yaca_key_destroy())
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo, bcm, sym_key_bits or pub_key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo, bcm, sym_key_bits or pub_key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see #yaca_block_cipher_mode_e
* @see yaca_seal_update()
- * @see yaca_seal_final()
- * @see yaca_key_free()
- * @see yaca_ctx_free()
+ * @see yaca_seal_finalize()
+ * @see yaca_key_destroy()
+ * @see yaca_context_destroy()
*/
-int yaca_seal_init(yaca_ctx_h *ctx,
- const yaca_key_h pub_key,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- yaca_key_bits_e sym_key_bits,
- yaca_key_h *sym_key,
- yaca_key_h *iv);
+int yaca_seal_initialize(yaca_context_h *ctx,
+ const yaca_key_h pub_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ yaca_key_bit_length_e sym_key_bits,
+ yaca_key_h *sym_key,
+ yaca_key_h *iv);
/**
* @brief Encrypts piece of the data.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_seal_init()
+ * @param[in,out] ctx Context created by yaca_seal_initialize()
* @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
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_seal_init()
- * @see yaca_seal_final()
+ * @see yaca_seal_initialize()
+ * @see yaca_seal_finalize()
* @see yaca_get_output_length()
*/
-int yaca_seal_update(yaca_ctx_h ctx,
+int yaca_seal_update(yaca_context_h ctx,
const char *plain,
size_t plain_len,
char *cipher,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_seal_init()
+ * @see yaca_seal_initialize()
* @see yaca_seal_update()
* @see yaca_get_block_length()
*/
-int yaca_seal_final(yaca_ctx_h ctx,
- char *cipher,
- size_t *cipher_len);
+int yaca_seal_finalize(yaca_context_h ctx,
+ char *cipher,
+ size_t *cipher_len);
/**
* @brief Initializes an asymmetric decryption context.
*
* @since_tizen 3.0
*
- * @param[out] ctx Newly created context (must be freed by yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed by yaca_context_destroy())
* @param[in] prv_key Private key, part of the pair that was used for the encryption
* @param[in] algo Symmetric algorithm that was used for the encryption
* @param[in] bcm Block chaining mode for the symmetric algorithm
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo, bcm, sym_key_bits, prv_key, sym_key or iv)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo, bcm, sym_key_bits, prv_key, sym_key or iv)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see #yaca_block_cipher_mode_e
* @see yaca_open_update()
- * @see yaca_open_final()
- * @see yaca_ctx_free()
+ * @see yaca_open_finalize()
+ * @see yaca_context_destroy()
*/
-int yaca_open_init(yaca_ctx_h *ctx,
- const yaca_key_h prv_key,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- yaca_key_bits_e sym_key_bits,
- const yaca_key_h sym_key,
- const yaca_key_h iv);
+int yaca_open_initialize(yaca_context_h *ctx,
+ const yaca_key_h prv_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ yaca_key_bit_length_e sym_key_bits,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
* @brief Decrypts piece of the data.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_open_init()
+ * @param[in,out] ctx Context created by yaca_open_initialize()
* @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
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_open_init()
- * @see yaca_open_final()
+ * @see yaca_open_initialize()
+ * @see yaca_open_finalize()
* @see yaca_get_output_length()
*/
-int yaca_open_update(yaca_ctx_h ctx,
+int yaca_open_update(yaca_context_h ctx,
const char *cipher,
size_t cipher_len,
char *plain,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_open_init()
+ * @see yaca_open_initialize()
* @see yaca_open_update()
* @see yaca_get_block_length()
*/
-int yaca_open_final(yaca_ctx_h ctx,
- char *plain,
- size_t *plain_len);
+int yaca_open_finalize(yaca_context_h ctx,
+ char *plain,
+ size_t *plain_len);
/**@}*/
*
* @since_tizen 3.0
*
- * @remarks For verification use yaca_verify_init(), yaca_verify_update() and
- * yaca_verify_final() functions with matching public key.
+ * @remarks For verification use yaca_verify_initialize(), yaca_verify_update() and
+ * yaca_verify_finalize() functions with matching public key.
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Digest algorithm that will be used
* @param[in] key Private key that will be used, algorithm is deduced based
* on key type, supported key types:
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_digest_algo_e
+ * @see #yaca_digest_algorithm_e
* @see yaca_sign_update()
- * @see yaca_sign_final()
- * @see yaca_verify_init()
+ * @see yaca_sign_finalize()
+ * @see yaca_verify_initialize()
* @see yaca_verify_update()
- * @see yaca_verify_final()
- * @see yaca_ctx_free()
+ * @see yaca_verify_finalize()
+ * @see yaca_context_destroy()
*/
-int yaca_sign_init(yaca_ctx_h *ctx,
- yaca_digest_algo_e algo,
- const yaca_key_h key);
+int yaca_sign_initialize(yaca_context_h *ctx,
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h key);
/**
* @brief Initializes a signature context for HMAC.
* @remarks For verification, calculate message HMAC and compare with received MAC using
* yaca_memcmp().
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Digest algorithm that will be used
* @param[in] key Symmetric key that will be used, supported key types:
* - #YACA_KEY_TYPE_SYMMETRIC,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_digest_algo_e
+ * @see #yaca_digest_algorithm_e
* @see yaca_sign_update()
- * @see yaca_sign_final()
+ * @see yaca_sign_finalize()
* @see yaca_memcmp()
- * @see yaca_ctx_free()
+ * @see yaca_context_destroy()
*/
-int yaca_sign_hmac_init(yaca_ctx_h *ctx,
- yaca_digest_algo_e algo,
- const yaca_key_h key);
+int yaca_sign_initialize_hmac(yaca_context_h *ctx,
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h key);
/**
* @brief Initializes a signature context for CMAC.
* @remarks For verification, calculate message CMAC and compare with received MAC using
* yaca_memcmp().
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Encryption algorithm that will be used
* @param[in] key Symmetric key that will be used, supported key types:
* - #YACA_KEY_TYPE_SYMMETRIC,
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see yaca_sign_update()
- * @see yaca_sign_final()
+ * @see yaca_sign_finalize()
* @see yaca_memcmp()
- * @see yaca_ctx_free()
+ * @see yaca_context_destroy()
*/
-int yaca_sign_cmac_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
- const yaca_key_h key);
+int yaca_sign_initialize_cmac(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
+ const yaca_key_h key);
/**
* @brief Feeds the data into the digital signature or MAC algorithm.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_sign_init(),
- * yaca_sign_hmac_init() or yaca_sign_cmac_init()
+ * @param[in,out] ctx Context created by yaca_sign_initialize(),
+ * yaca_sign_initialize_hmac() or yaca_sign_initialize_cmac()
* @param[in] data Data to be signed
* @param[in] data_len Length of the data
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_sign_init()
- * @see yaca_sign_final()
- * @see yaca_sign_hmac_init()
- * @see yaca_sign_cmac_init()
+ * @see yaca_sign_initialize()
+ * @see yaca_sign_finalize()
+ * @see yaca_sign_initialize_hmac()
+ * @see yaca_sign_initialize_cmac()
*/
-int yaca_sign_update(yaca_ctx_h ctx,
+int yaca_sign_update(yaca_context_h ctx,
const char *data,
size_t data_len);
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_sign_init()
+ * @see yaca_sign_initialize()
* @see yaca_sign_update()
- * @see yaca_sign_hmac_init()
- * @see yaca_sign_cmac_init()
+ * @see yaca_sign_initialize_hmac()
+ * @see yaca_sign_initialize_cmac()
* @see yaca_get_sign_length()
*/
-int yaca_sign_final(yaca_ctx_h ctx,
- char *signature,
- size_t *signature_len);
+int yaca_sign_finalize(yaca_context_h ctx,
+ char *signature,
+ size_t *signature_len);
/**
* @brief Initializes a signature verification context for asymmetric signatures
*
* @since_tizen 3.0
*
- * @param[out] ctx Newly created context (must be freed with yaca_ctx_free())
+ * @param[out] ctx Newly created context (must be freed with yaca_context_destroy())
* @param[in] algo Digest algorithm that will be used
* @param[in] key Public key that will be used, algorithm is deduced based on
* key type, supported key types:
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_digest_algo_e
+ * @see #yaca_digest_algorithm_e
* @see yaca_verify_update()
- * @see yaca_verify_final()
- * @see yaca_ctx_free()
+ * @see yaca_verify_finalize()
+ * @see yaca_context_destroy()
*/
-int yaca_verify_init(yaca_ctx_h *ctx,
- yaca_digest_algo_e algo,
- const yaca_key_h key);
+int yaca_verify_initialize(yaca_context_h *ctx,
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h key);
/**
* @brief Feeds the data into the digital signature verification algorithm.
*
* @since_tizen 3.0
*
- * @param[in,out] ctx Context created by yaca_verify_init()
+ * @param[in,out] ctx Context created by yaca_verify_initialize()
* @param[in] data Data to be verified
* @param[in] data_len Length of the data
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see yaca_verify_init()
- * @see yaca_verify_final()
+ * @see yaca_verify_initialize()
+ * @see yaca_verify_finalize()
*/
-int yaca_verify_update(yaca_ctx_h ctx,
+int yaca_verify_update(yaca_context_h ctx,
const char *data,
size_t data_len);
* @since_tizen 3.0
*
* @param[in,out] ctx A valid verify context
- * @param[in] signature Input signature (returned by yaca_sign_final())
+ * @param[in] signature Input signature (returned by yaca_sign_finalize())
* @param[in] signature_len Size of the signature
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL,
- * invalid context)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
+ * invalid context)
* @retval #YACA_ERROR_INTERNAL Internal error
* @retval #YACA_ERROR_DATA_MISMATCH The verification failed
*
- * @see yaca_verify_init()
+ * @see yaca_verify_initialize()
* @see yaca_verify_update()
- * @see yaca_sign_final()
+ * @see yaca_sign_finalize()
*/
-int yaca_verify_final(yaca_ctx_h ctx,
- const char *signature,
- size_t signature_len);
+int yaca_verify_finalize(yaca_context_h ctx,
+ const char *signature,
+ size_t signature_len);
/**@}*/
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_digest_algo_e
+ * @see #yaca_digest_algorithm_e
* @see yaca_free()
*/
-int yaca_digest_calc(yaca_digest_algo_e algo,
- const char *data,
- size_t data_len,
- char **digest,
- size_t *digest_len);
+int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
+ const char *data,
+ size_t data_len,
+ char **digest,
+ size_t *digest_len);
/**
* @brief Encrypt data using a symmetric cipher.
*
* @since_tizen 3.0
*
- * @param[in] algo Encryption algorithm (select #YACA_ENC_AES if unsure)
+ * @param[in] algo Encryption algorithm (select #YACA_ENCRYPT_AES if unsure)
* @param[in] bcm Chaining mode (select #YACA_BCM_CBC if unsure)
* @param[in] sym_key Symmetric encryption key (see key.h for key generation functions)
* @param[in] iv Initialization vector
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo, bcm, sym_key or iv)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo, bcm, sym_key or iv)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see #yaca_block_cipher_mode_e
- * @see yaca_decrypt()
+ * @see yaca_simple_decrypt()
* @see yaca_free()
*/
-int yaca_encrypt(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *plain,
- size_t plain_len,
- char **cipher,
- size_t *cipher_len);
+int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *plain,
+ size_t plain_len,
+ char **cipher,
+ size_t *cipher_len);
/**
* @brief Decrypt data using a symmetric cipher.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo, bcm, sym_key or iv)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo, bcm, sym_key or iv)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see #yaca_block_cipher_mode_e
- * @see yaca_encrypt()
+ * @see yaca_simple_encrypt()
* @see yaca_free()
*/
-int yaca_decrypt(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *cipher,
- size_t cipher_len,
- char **plain,
- size_t *plain_len);
+int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *cipher,
+ size_t cipher_len,
+ char **plain,
+ size_t *plain_len);
/**
* @brief Create a signature using asymmetric private key.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_digest_algo_e
- * @see yaca_verify()
+ * @see #yaca_digest_algorithm_e
+ * @see yaca_simple_verify_signature()
* @see yaca_free()
*/
-int yaca_sign(yaca_digest_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- char **signature,
- size_t *signature_len);
+int yaca_simple_calculate_signature(yaca_digest_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ char **signature,
+ size_t *signature_len);
/**
* @brief Verify a signature using asymmetric public key.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
* @retval #YACA_ERROR_DATA_MISMATCH The verification failed
*
* @see #yaca_key_type_e
- * @see #yaca_digest_algo_e
- * @see yaca_sign()
+ * @see #yaca_digest_algorithm_e
+ * @see yaca_simple_calculate_signature()
*/
-int yaca_verify(yaca_digest_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- const char *signature,
- size_t signature_len);
+int yaca_simple_verify_signature(yaca_digest_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ const char *signature,
+ size_t signature_len);
/**
* @brief Calculate a HMAC of given message using symmetric key.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_digest_algo_e
+ * @see #yaca_digest_algorithm_e
* @see yaca_memcmp()
* @see yaca_free()
*/
-int yaca_hmac(yaca_digest_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- char **mac,
- size_t *mac_len);
+int yaca_simple_calculate_hmac(yaca_digest_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ char **mac,
+ size_t *mac_len);
/**
* @brief Calculate a CMAC of given message using symmetric key.
*
* @return #YACA_ERROR_NONE on success, negative on error
* @retval #YACA_ERROR_NONE Successful
- * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have incorrect values (NULL, 0
- * invalid algo or key)
+ * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0
+ * invalid algo or key)
* @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
* @retval #YACA_ERROR_INTERNAL Internal error
*
* @see #yaca_key_type_e
- * @see #yaca_enc_algo_e
+ * @see #yaca_encrypt_algorithm_e
* @see yaca_memcmp()
* @see yaca_free()
*/
-int yaca_cmac(yaca_enc_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- char **mac,
- size_t *mac_len);
+int yaca_simple_calculate_cmac(yaca_encrypt_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ char **mac,
+ size_t *mac_len);
/**@}*/
*
* @since_tizen 3.0
*/
-typedef struct yaca_ctx_s *yaca_ctx_h;
+typedef struct yaca_context_s *yaca_context_h;
/**
* @brief Key.
YACA_KEY_FORMAT_DEFAULT,
/** Key is in PKCS#8, can only be used for asymmetric private keys */
YACA_KEY_FORMAT_PKCS8
-} yaca_key_fmt_e;
+} yaca_key_format_e;
/**
* @brief Enumeration of YACA key file formats.
YACA_KEY_FILE_FORMAT_PEM,
/** Key file is in DER file format, used for asymmetric keys */
YACA_KEY_FILE_FORMAT_DER
-} yaca_key_file_fmt_e;
+} yaca_key_file_format_e;
/**
* @brief Enumeration of YACA key types, IV is considered as key.
/**
* @brief Enumeration of YACA key lengths.
* It is possible to use arbitrary integer instead,
- * this enums are placed here to avoid magic numbers.
+ * this enum values are placed here to avoid magic numbers.
*
* @since_tizen 3.0
*/
typedef enum {
- YACA_KEY_IV_UNSAFE_24BIT = 24,
- YACA_KEY_IV_64BIT = 64,
- YACA_KEY_IV_128BIT = 128,
- YACA_KEY_IV_256BIT = 256,
- YACA_KEY_UNSAFE_8BIT = 8,
- YACA_KEY_UNSAFE_40BIT = 40,
- YACA_KEY_UNSAFE_64BIT = 64,
- YACA_KEY_UNSAFE_80BIT = 80,
- YACA_KEY_UNSAFE_128BIT = 128,
- YACA_KEY_192BIT = 192,
- YACA_KEY_256BIT = 256,
- YACA_KEY_512BIT = 512,
- YACA_KEY_1024BIT = 1024,
- YACA_KEY_2048BIT = 2048,
- YACA_KEY_3072BIT = 3072,
- YACA_KEY_4096BIT = 4096
-} yaca_key_bits_e;
+ YACA_KEY_LENGTH_IV_UNSAFE_24BIT = 24,
+ YACA_KEY_LENGTH_IV_64BIT = 64,
+ YACA_KEY_LENGTH_IV_128BIT = 128,
+ YACA_KEY_LENGTH_IV_256BIT = 256,
+ YACA_KEY_LENGTH_UNSAFE_8BIT = 8,
+ YACA_KEY_LENGTH_UNSAFE_40BIT = 40,
+ YACA_KEY_LENGTH_UNSAFE_64BIT = 64,
+ YACA_KEY_LENGTH_UNSAFE_80BIT = 80,
+ YACA_KEY_LENGTH_UNSAFE_128BIT = 128,
+ YACA_KEY_LENGTH_192BIT = 192,
+ YACA_KEY_LENGTH_256BIT = 256,
+ YACA_KEY_LENGTH_512BIT = 512,
+ YACA_KEY_LENGTH_1024BIT = 1024,
+ YACA_KEY_LENGTH_2048BIT = 2048,
+ YACA_KEY_LENGTH_3072BIT = 3072,
+ YACA_KEY_LENGTH_4096BIT = 4096
+} yaca_key_bit_length_e;
/**
* @brief Enumeration of YACA message digest algorithms.
YACA_DIGEST_SHA384,
/** Message digest algorithm SHA2, 512bit */
YACA_DIGEST_SHA512,
-} yaca_digest_algo_e;
+} yaca_digest_algorithm_e;
/**
* @brief Enumeration of YACA symmetric encryption algorithms.
* #YACA_BCM_CTR
* - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory).
*/
- YACA_ENC_AES = 0,
+ YACA_ENCRYPT_AES = 0,
/**
* DES encryption.
* #YACA_BCM_ECB
* - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory).
*/
- YACA_ENC_UNSAFE_DES,
+ YACA_ENCRYPT_UNSAFE_DES,
/**
* 3DES 2-key encryption.
* - Use double DES keys to perform corresponding 2-key 3DES encryption.
*/
- YACA_ENC_UNSAFE_3DES_2TDEA,
+ YACA_ENCRYPT_UNSAFE_3DES_2TDEA,
/**
* 3DES 3-key encryption.
* - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory).
* - Use triple DES keys to perform corresponding 3-key 3DES encryption.
*/
- YACA_ENC_3DES_3TDEA,
+ YACA_ENCRYPT_3DES_3TDEA,
/**
* RC2 encryption.
* #YACA_BCM_CFB,
* #YACA_BCM_ECB
*/
- YACA_ENC_UNSAFE_RC2,
+ YACA_ENCRYPT_UNSAFE_RC2,
/**
* RC4 encryption.
* - Supported key lengths: 40–2048 bits in steps of 8 bits.
* This cipher doesn't support block cipher modes, use #YACA_BCM_NONE instead.
*/
- YACA_ENC_UNSAFE_RC4,
+ YACA_ENCRYPT_UNSAFE_RC4,
/**
* CAST5 encryption.
* #YACA_BCM_ECB
* - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory).
*/
- YACA_ENC_CAST5,
-} yaca_enc_algo_e;
+ YACA_ENCRYPT_CAST5,
+} yaca_encrypt_algorithm_e;
/**
* @brief Enumeration of YACA chaining modes for block ciphers.
* This is a variable IV length mode (recommended 96 bits IV).
*
* Supported parameters:
- * - #YACA_PARAM_GCM_TAG_LEN = GCM tag length\n
+ * - #YACA_PROPERTY_GCM_TAG_LEN = GCM tag length\n
* Supported tag lengths: @c 32, @c 64, @c 96, @c 104, @c 112, @c 120, @c 128,
* (recommended 128 bits tag).\n
- * Set after yaca_encrypt_final() and before yaca_ctx_get_param(#YACA_PARAM_GCM_TAG)
+ * Set after yaca_encrypt_finalize() and before yaca_context_get_property(#YACA_PROPERTY_GCM_TAG)
* in encryption operation.\n\n
*
- * - #YACA_PARAM_GCM_TAG = GCM tag\n
- * Get after yaca_encrypt_final() in encryption operation.\n
- * Set before yaca_decrypt_final() in decryption operation.\n\n
+ * - #YACA_PROPERTY_GCM_TAG = GCM tag\n
+ * Get after yaca_encrypt_finalize() in encryption operation.\n
+ * Set before yaca_decrypt_finalize() in decryption operation.\n\n
*
- * - #YACA_PARAM_GCM_AAD = additional authentication data (optional)\n
- * Set after yaca_encrypt_init() and before yaca_encrypt_update()
+ * - #YACA_PROPERTY_GCM_AAD = additional authentication data (optional)\n
+ * Set after yaca_encrypt_initialize() and before yaca_encrypt_update()
* in encryption operation.\n
- * Set after yaca_decrypt_init() and before yaca_decrypt_update()
+ * Set after yaca_decrypt_initialize() and before yaca_decrypt_update()
* in decryption operation.\n\n
*
* @see examples/encrypt_aes_gcm_ccm.c
* Supported IV lengths: 56-104 bits in steps of 8 bits (recommended 56 bits IV).\n\n
*
* Supported parameters:
- * - #YACA_PARAM_CCM_TAG_LEN = CCM tag length\n
+ * - #YACA_PROPERTY_CCM_TAG_LEN = CCM tag length\n
* Supported tag lengths: 32-128 bits in step of 16 bits (recommended 96 bits tag).\n
- * Set after yaca_encrypt_init() and before yaca_encrypt_update()
+ * Set after yaca_encrypt_initialize() and before yaca_encrypt_update()
* in encryption operation.\n\n
*
- * - #YACA_PARAM_CCM_TAG = CCM tag\n
- * Get after yaca_encrypt_final() in encryption operation.\n
- * Set after yaca_decrypt_init() and before yaca_decrypt_update()
+ * - #YACA_PROPERTY_CCM_TAG = CCM tag\n
+ * Get after yaca_encrypt_finalize() in encryption operation.\n
+ * Set after yaca_decrypt_initialize() and before yaca_decrypt_update()
* in decryption operation.\n\n
*
- * - #YACA_PARAM_CCM_AAD = additional authentication data (optional)\n
+ * - #YACA_PROPERTY_CCM_AAD = additional authentication data (optional)\n
* The total plain text length must be passed to yaca_encrypt_update()
* if AAD is used.\n
- * Set after yaca_encrypt_init() and before yaca_encrypt_update()
+ * Set after yaca_encrypt_initialize() and before yaca_encrypt_update()
* in encryption operation.\n
* You can only call yaca_encrypt_update() once for AAD and once for the plain text.\n\n
*
* The total encrypted text length must be passed to yaca_decrypt_update()
* if AAD is used.\n
- * Set after yaca_decrypt_init() and before yaca_decrypt_update()
+ * Set after yaca_decrypt_initialize() and before yaca_decrypt_update()
* in decryption operation.\n\n
*
* @see examples/encrypt_aes_gcm_ccm.c
/**
- * @brief Enumeration of YACA non-standard parameters for algorithms.
+ * @brief Enumeration of YACA non-standard properties for algorithms.
*
* @since_tizen 3.0
*/
typedef enum {
/** Padding */
- YACA_PARAM_PADDING,
+ YACA_PROPERTY_PADDING,
/** GCM Additional Authentication Data */
- YACA_PARAM_GCM_AAD,
+ YACA_PROPERTY_GCM_AAD,
/** GCM Tag bits */
- YACA_PARAM_GCM_TAG,
+ YACA_PROPERTY_GCM_TAG,
/** GCM Tag length */
- YACA_PARAM_GCM_TAG_LEN,
+ YACA_PROPERTY_GCM_TAG_LEN,
/** CCM Additional Authentication Data */
- YACA_PARAM_CCM_AAD,
+ YACA_PROPERTY_CCM_AAD,
/** CCM Tag bits */
- YACA_PARAM_CCM_TAG,
+ YACA_PROPERTY_CCM_TAG,
/** CCM Tag length */
- YACA_PARAM_CCM_TAG_LEN
-} yaca_ex_param_e;
+ YACA_PROPERTY_CCM_TAG_LEN
+} yaca_property_e;
/**
* @brief Enumeration of YACA paddings.
char *digest;
size_t digest_len;
- ret = yaca_digest_calc(YACA_DIGEST_SHA256,
+ ret = yaca_simple_calculate_digest(YACA_DIGEST_SHA256,
lorem1024,
1024, &digest, &digest_len);
if (ret != YACA_ERROR_NONE)
void digest_advanced(void)
{
int ret = YACA_ERROR_NONE;
- yaca_ctx_h ctx;
+ yaca_context_h ctx;
- ret = yaca_digest_init(&ctx, YACA_DIGEST_SHA256);
+ ret = yaca_digest_initialize(&ctx, YACA_DIGEST_SHA256);
if (ret != YACA_ERROR_NONE)
return;
{
char digest[digest_len];
- ret = yaca_digest_final(ctx, digest, &digest_len);
+ ret = yaca_digest_finalize(ctx, digest, &digest_len);
if (ret != YACA_ERROR_NONE)
goto exit;
}
exit:
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
}
int main()
{
yaca_debug_set_error_cb(debug_func);
- int ret = yaca_init();
+ int ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
digest_advanced();
- yaca_exit();
+ yaca_cleanup();
return ret;
}
#include "misc.h"
#include "../src/debug.h"
-void encrypt_simple(const yaca_enc_algo_e algo,
+void encrypt_simple(const yaca_encrypt_algorithm_e algo,
const yaca_block_cipher_mode_e bcm,
const size_t key_bits)
{
YACA_DIGEST_SHA256, key_bits, &key) != YACA_ERROR_NONE)
return;
- if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE)
+ if (yaca_encrypt_get_iv_bit_length(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE)
goto exit;
- if (iv_bits > 0 && yaca_key_gen(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+ if (iv_bits > 0 && yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
goto exit;
- if (yaca_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_size) != YACA_ERROR_NONE)
+ if (yaca_simple_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_size) != YACA_ERROR_NONE)
goto exit;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- if (yaca_decrypt(algo, bcm, key, iv, enc, enc_size, &dec, &dec_size) != YACA_ERROR_NONE)
+ if (yaca_simple_decrypt(algo, bcm, key, iv, enc, enc_size, &dec, &dec_size) != YACA_ERROR_NONE)
goto exit;
printf("Decrypted data (16 of %zu bytes): %.16s\n\n", dec_size, dec);
exit:
yaca_free(enc);
yaca_free(dec);
- yaca_key_free(iv);
- yaca_key_free(key);
+ yaca_key_destroy(iv);
+ yaca_key_destroy(key);
}
-void encrypt_advanced(const yaca_enc_algo_e algo,
+void encrypt_advanced(const yaca_encrypt_algorithm_e algo,
const yaca_block_cipher_mode_e bcm,
const yaca_key_type_e key_type,
const size_t key_bits)
{
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h key = YACA_KEY_NULL;
yaca_key_h iv = YACA_KEY_NULL;
size_t iv_bits;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
/* Key generation */
- if (yaca_key_gen(key_type, key_bits, &key) != YACA_ERROR_NONE)
+ if (yaca_key_generate(key_type, key_bits, &key) != YACA_ERROR_NONE)
return;
- if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE)
+ if (yaca_encrypt_get_iv_bit_length(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE)
goto exit;
- if (iv_bits > 0 && yaca_key_gen(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+ if (iv_bits > 0 && yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
goto exit;
/* Encryption */
{
- if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
+ 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)
goto exit;
rem = enc_size - out_size;
- if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_encrypt_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
enc_size = rem + out_size;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
}
/* Decryption */
{
- if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
+ 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)
goto exit;
rem = dec_size - out_size;
- if (yaca_decrypt_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_decrypt_finalize(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
dec_size = rem + out_size;
exit:
yaca_free(dec);
yaca_free(enc);
- yaca_ctx_free(ctx);
- yaca_key_free(iv);
- yaca_key_free(key);
+ yaca_context_destroy(ctx);
+ yaca_key_destroy(iv);
+ yaca_key_destroy(key);
}
int main()
{
yaca_debug_set_error_cb(debug_func);
- int ret = yaca_init();
+ int ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
- yaca_enc_algo_e algo = YACA_ENC_AES;
+ yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
yaca_block_cipher_mode_e bcm = YACA_BCM_ECB;
yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
- size_t key_bits = YACA_KEY_256BIT;
+ size_t key_bits = YACA_KEY_LENGTH_256BIT;
encrypt_simple(algo, bcm, key_bits);
encrypt_advanced(algo, bcm, key_type, key_bits);
- algo = YACA_ENC_3DES_3TDEA;
+ algo = YACA_ENCRYPT_3DES_3TDEA;
bcm = YACA_BCM_OFB;
key_type = YACA_KEY_TYPE_DES;
- key_bits = YACA_KEY_192BIT;
+ key_bits = YACA_KEY_LENGTH_192BIT;
encrypt_advanced(algo, bcm, key_type, key_bits);
- algo = YACA_ENC_CAST5;
+ algo = YACA_ENCRYPT_CAST5;
bcm = YACA_BCM_CFB;
key_type = YACA_KEY_TYPE_SYMMETRIC;
- key_bits = YACA_KEY_UNSAFE_40BIT;
+ key_bits = YACA_KEY_LENGTH_UNSAFE_40BIT;
encrypt_simple(algo, bcm, key_bits);
encrypt_advanced(algo, bcm, key_type, key_bits);
- algo = YACA_ENC_UNSAFE_RC2;
+ algo = YACA_ENCRYPT_UNSAFE_RC2;
bcm = YACA_BCM_CBC;
key_type = YACA_KEY_TYPE_SYMMETRIC;
- key_bits = YACA_KEY_UNSAFE_8BIT;
+ key_bits = YACA_KEY_LENGTH_UNSAFE_8BIT;
encrypt_simple(algo, bcm, key_bits);
encrypt_advanced(algo, bcm, key_type, key_bits);
- algo = YACA_ENC_UNSAFE_RC4;
+ algo = YACA_ENCRYPT_UNSAFE_RC4;
bcm = YACA_BCM_NONE;
key_type = YACA_KEY_TYPE_SYMMETRIC;
- key_bits = YACA_KEY_2048BIT;
+ key_bits = YACA_KEY_LENGTH_2048BIT;
encrypt_simple(algo, bcm, key_bits);
encrypt_advanced(algo, bcm, key_type, key_bits);
- yaca_exit();
+ yaca_cleanup();
return ret;
}
void encrypt_decrypt_aes_gcm(void)
{
- yaca_enc_algo_e algo = YACA_ENC_AES;
+ yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
yaca_block_cipher_mode_e bcm = YACA_BCM_GCM;
yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
- size_t key_bits = YACA_KEY_256BIT;
- size_t iv_bits = YACA_KEY_IV_128BIT;
+ size_t key_bits = YACA_KEY_LENGTH_256BIT;
+ size_t iv_bits = YACA_KEY_LENGTH_IV_128BIT;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h key = YACA_KEY_NULL;
yaca_key_h iv = YACA_KEY_NULL;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
/* Key generation */
- if (yaca_key_gen(key_type, key_bits, &key) != YACA_ERROR_NONE)
+ if (yaca_key_generate(key_type, key_bits, &key) != YACA_ERROR_NONE)
return;
/* IV generation */
- if (yaca_key_gen(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+ if (yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
goto exit;
if (yaca_zalloc(aad_size, (void**)&aad) != YACA_ERROR_NONE)
goto exit;
- if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE)
+ if (yaca_randomize_bytes(aad, aad_size) != YACA_ERROR_NONE)
goto exit;
if (yaca_zalloc(tag_size, (void**)&tag) != YACA_ERROR_NONE)
/* Encryption */
{
- if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
+ if (yaca_encrypt_initialize(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
goto exit;
/* Provide any AAD data */
- if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+ 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)
goto exit;
rem = enc_size - out_size;
- if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_encrypt_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
enc_size = rem + out_size;
/* Set the tag length and get the tag after final encryption */
- if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG_LEN,
+ if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG_LEN,
(void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE)
goto exit;
- if (yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE)
+ if (yaca_context_get_property(ctx, YACA_PROPERTY_GCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE)
goto exit;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
}
/* Decryption */
{
- if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
+ if (yaca_decrypt_initialize(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
goto exit;
/* Provide any AAD data */
- if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+ 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)
rem = dec_size - out_size;
/* Set expected tag value before final decryption */
- if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG, tag, tag_size) != YACA_ERROR_NONE)
+ if (yaca_context_set_property(ctx, YACA_PROPERTY_GCM_TAG, tag, tag_size) != YACA_ERROR_NONE)
goto exit;
- if (yaca_decrypt_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_decrypt_finalize(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
dec_size = rem + out_size;
yaca_free(dec);
yaca_free(tag);
yaca_free(aad);
- yaca_ctx_free(ctx);
- yaca_key_free(iv);
- yaca_key_free(key);
+ yaca_context_destroy(ctx);
+ yaca_key_destroy(iv);
+ yaca_key_destroy(key);
}
void encrypt_decrypt_aes_ccm(void)
{
- yaca_enc_algo_e algo = YACA_ENC_AES;
+ yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
yaca_block_cipher_mode_e bcm = YACA_BCM_CCM;
yaca_key_type_e key_type = YACA_KEY_TYPE_SYMMETRIC;
- size_t key_bits = YACA_KEY_256BIT;
- size_t iv_bits = YACA_KEY_IV_64BIT;
+ size_t key_bits = YACA_KEY_LENGTH_256BIT;
+ size_t iv_bits = YACA_KEY_LENGTH_IV_64BIT;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h key = YACA_KEY_NULL;
yaca_key_h iv = YACA_KEY_NULL;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
/* Key generation */
- if (yaca_key_gen(key_type, key_bits, &key) != YACA_ERROR_NONE)
+ if (yaca_key_generate(key_type, key_bits, &key) != YACA_ERROR_NONE)
return;
/* IV generation */
- if (yaca_key_gen(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
+ if (yaca_key_generate(YACA_KEY_TYPE_IV, iv_bits, &iv) != YACA_ERROR_NONE)
goto exit;
if (yaca_zalloc(aad_size, (void**)&aad) != YACA_ERROR_NONE)
goto exit;
- if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE)
+ if (yaca_randomize_bytes(aad, aad_size) != YACA_ERROR_NONE)
goto exit;
if (yaca_zalloc(tag_size, (void**)&tag) != YACA_ERROR_NONE)
/* Encryption */
{
- if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
+ if (yaca_encrypt_initialize(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
goto exit;
/* Set tag length (optionally) */
- if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG_LEN,
+ if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_TAG_LEN,
(void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE)
goto exit;
if (yaca_encrypt_update(ctx, NULL, LOREM4096_SIZE , NULL, &len) != YACA_ERROR_NONE)
goto exit;
- if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+ 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)
goto exit;
rem = enc_size - out_size;
- if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_encrypt_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
enc_size = rem + out_size;
/* Get the tag after final encryption */
- if (yaca_ctx_get_param(ctx, YACA_PARAM_CCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE)
+ if (yaca_context_get_property(ctx, YACA_PROPERTY_CCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE)
goto exit;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
}
/* Decryption */
{
- if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
+ if (yaca_decrypt_initialize(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE)
goto exit;
/* Set expected tag value */
- if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG, tag, tag_size) != YACA_ERROR_NONE)
+ if (yaca_context_set_property(ctx, YACA_PROPERTY_CCM_TAG, tag, tag_size) != YACA_ERROR_NONE)
goto exit;
/* The total encrypted text length must be passed (only needed if AAD is passed) */
if (yaca_decrypt_update(ctx, NULL, enc_size , NULL, &len) != YACA_ERROR_NONE)
goto exit;
- if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE)
+ 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)
out_size = dec_size;
/* The tag verify is performed when you call the final yaca_decrypt_update(),
- * there is no call to yaca_decrypt_final() */
+ * there is no call to yaca_decrypt_finalize() */
if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE)
goto exit;
yaca_free(dec);
yaca_free(tag);
yaca_free(aad);
- yaca_ctx_free(ctx);
- yaca_key_free(iv);
- yaca_key_free(key);
+ yaca_context_destroy(ctx);
+ yaca_key_destroy(iv);
+ yaca_key_destroy(key);
}
int main()
{
yaca_debug_set_error_cb(debug_func);
- int ret = yaca_init();
+ int ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
encrypt_decrypt_aes_gcm();
encrypt_decrypt_aes_ccm();
- yaca_exit();
+ yaca_cleanup();
return ret;
}
long size;
// generate private, public key
- ret = yaca_key_gen(YACA_KEY_TYPE_DH_PRIV, YACA_KEY_2048BIT, &private_key);
+ ret = yaca_key_generate(YACA_KEY_TYPE_DH_PRIV, YACA_KEY_LENGTH_2048BIT, &private_key);
if (ret != YACA_ERROR_NONE)
goto exit;
goto exit;
exit:
- yaca_key_free(private_key);
- yaca_key_free(public_key);
- yaca_key_free(peer_key);
- yaca_key_free(secret);
+ yaca_key_destroy(private_key);
+ yaca_key_destroy(public_key);
+ yaca_key_destroy(peer_key);
+ yaca_key_destroy(secret);
if (fp != NULL)
fclose(fp);
yaca_free(buffer);
long size;
// generate private, public key
- ret = yaca_key_gen(YACA_KEY_TYPE_EC_PRIV, YACA_KEY_CURVE_P256, &private_key);
+ ret = yaca_key_generate(YACA_KEY_TYPE_EC_PRIV, YACA_KEY_CURVE_P256, &private_key);
if (ret != YACA_ERROR_NONE)
goto exit;
goto exit;
exit:
- yaca_key_free(private_key);
- yaca_key_free(public_key);
- yaca_key_free(peer_key);
- yaca_key_free(secret);
+ yaca_key_destroy(private_key);
+ yaca_key_destroy(public_key);
+ yaca_key_destroy(peer_key);
+ yaca_key_destroy(secret);
if (fp != NULL)
fclose(fp);
yaca_free(buffer);
{
yaca_debug_set_error_cb(debug_func);
- int ret = yaca_init();
+ int ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
key_exchange_dh();
key_exchange_ecdh();
- yaca_exit();
+ yaca_cleanup();
return ret;
}
dump_hex(raw, raw_len, "\t***** RAW imported key: *****");
exit:
- yaca_key_free(raw_imported);
- yaca_key_free(b64_imported);
+ yaca_key_destroy(raw_imported);
+ yaca_key_destroy(b64_imported);
yaca_free(raw);
yaca_free(b64);
dump_hex(der_pub, der_pub_len, "\t***** %s DER imported public key: *****", algo);
exit:
- yaca_key_free(der_pub_imported);
- yaca_key_free(pem_pub_imported);
- yaca_key_free(der_prv_imported);
- yaca_key_free(pem_prv_imported);
+ yaca_key_destroy(der_pub_imported);
+ yaca_key_destroy(pem_pub_imported);
+ yaca_key_destroy(der_prv_imported);
+ yaca_key_destroy(pem_prv_imported);
yaca_free(der_pub);
yaca_free(pem_pub);
yaca_free(der_prv);
printf("\n\t***** RSA X509 imported public key: *****\n%.*s", (int)pub_len, pub);
exit:
- yaca_key_free(rsa_pub_from_cert);
+ yaca_key_destroy(rsa_pub_from_cert);
yaca_free(pub);
return ret;
yaca_key_h dsa_pub = YACA_KEY_NULL;
int ret;
- ret = yaca_init();
+ ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
yaca_debug_set_error_cb(debug_func);
- ret = yaca_key_gen(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_1024BIT, &sym);
+ ret = yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_1024BIT, &sym);
if (ret != YACA_ERROR_NONE)
goto exit;
- ret = yaca_key_gen(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_1024BIT, &rsa_priv);
+ ret = yaca_key_generate(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_LENGTH_1024BIT, &rsa_priv);
if (ret != YACA_ERROR_NONE)
goto exit;
if (ret != YACA_ERROR_NONE)
goto exit;
- ret = yaca_key_gen(YACA_KEY_TYPE_DSA_PRIV, YACA_KEY_1024BIT, &dsa_priv);
+ ret = yaca_key_generate(YACA_KEY_TYPE_DSA_PRIV, YACA_KEY_LENGTH_1024BIT, &dsa_priv);
if (ret != YACA_ERROR_NONE)
goto exit;
printf("\n\t*********** X509 - failure ************\n\n");
exit:
- yaca_key_free(dsa_pub);
- yaca_key_free(dsa_priv);
- yaca_key_free(rsa_pub);
- yaca_key_free(rsa_priv);
- yaca_key_free(sym);
+ yaca_key_destroy(dsa_pub);
+ yaca_key_destroy(dsa_priv);
+ yaca_key_destroy(rsa_pub);
+ yaca_key_destroy(rsa_priv);
+ yaca_key_destroy(sym);
- yaca_exit();
+ yaca_cleanup();
return ret;
}
#include "misc.h"
#include "../src/debug.h"
-void example_password(const yaca_key_h key, yaca_key_fmt_e key_fmt)
+void example_password(const yaca_key_h key, yaca_key_format_e key_fmt)
{
char *k = NULL;
size_t kl;
password = NULL;
ret = yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, NULL, k, kl, &lkey);
- if (ret == YACA_ERROR_PASSWORD_INVALID) {
+ if (ret == YACA_ERROR_INVALID_PASSWORD) {
ret = read_stdin_line("decryption pass: ", &password);
if (ret != YACA_ERROR_NONE)
goto exit;
ret = yaca_key_import(YACA_KEY_TYPE_RSA_PRIV, password, k, kl, &lkey);
- if (ret == YACA_ERROR_PASSWORD_INVALID)
+ if (ret == YACA_ERROR_INVALID_PASSWORD)
printf("invalid password\n");
yaca_free(password);
exit:
yaca_free(k);
yaca_free(password);
- yaca_key_free(lkey);
+ yaca_key_destroy(lkey);
}
int main(int argc, char *argv[])
yaca_debug_set_error_cb(debug_func);
- ret = yaca_init();
+ ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
goto exit;
- ret = yaca_key_gen(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_1024BIT, &key);
+ ret = yaca_key_generate(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_LENGTH_1024BIT, &key);
if (ret != YACA_ERROR_NONE)
goto exit;
example_password(key, YACA_KEY_FORMAT_PKCS8);
exit:
- yaca_key_free(key);
- yaca_exit();
+ yaca_key_destroy(key);
+ yaca_cleanup();
return 0;
}
void encrypt_seal(void)
{
- const yaca_enc_algo_e algo = YACA_ENC_AES;
+ const yaca_encrypt_algorithm_e algo = YACA_ENCRYPT_AES;
const yaca_block_cipher_mode_e bcm = YACA_BCM_CBC;
- const size_t key_bits = YACA_KEY_256BIT;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ const size_t key_bits = YACA_KEY_LENGTH_256BIT;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h key_pub = YACA_KEY_NULL;
yaca_key_h key_priv = YACA_KEY_NULL;
yaca_key_h aes_key = YACA_KEY_NULL;
printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096);
/* Generate key pair */
- if (yaca_key_gen(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_4096BIT, &key_priv) != YACA_ERROR_NONE)
+ if (yaca_key_generate(YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_LENGTH_4096BIT, &key_priv) != YACA_ERROR_NONE)
return;
if (yaca_key_extract_public(key_priv, &key_pub) != YACA_ERROR_NONE)
/* Encrypt a.k.a. seal */
{
- if (yaca_seal_init(&ctx, key_pub, algo, bcm, key_bits, &aes_key, &iv) != YACA_ERROR_NONE)
+ 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)
goto exit;
rem = enc_size - out_size;
- if (yaca_seal_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_seal_finalize(ctx, enc + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
enc_size = rem + out_size;
dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size);
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
}
/* Decrypt a.k.a. open */
{
- if (yaca_open_init(&ctx, key_priv, algo, bcm, key_bits, aes_key, iv) != YACA_ERROR_NONE)
+ 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)
goto exit;
rem = dec_size - out_size;
- if (yaca_open_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
+ if (yaca_open_finalize(ctx, dec + out_size, &rem) != YACA_ERROR_NONE)
goto exit;
dec_size = rem + out_size;
exit:
yaca_free(dec);
yaca_free(enc);
- yaca_ctx_free(ctx);
- yaca_key_free(aes_key);
- yaca_key_free(iv);
- yaca_key_free(key_pub);
- yaca_key_free(key_priv);
+ yaca_context_destroy(ctx);
+ yaca_key_destroy(aes_key);
+ yaca_key_destroy(iv);
+ yaca_key_destroy(key_pub);
+ yaca_key_destroy(key_priv);
}
int main()
{
yaca_debug_set_error_cb(debug_func);
- int ret = yaca_init();
+ int ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
encrypt_seal();
- yaca_exit();
+ yaca_cleanup();
return ret;
}
yaca_key_h pub = YACA_KEY_NULL;
// GENERATE
- if (yaca_key_gen(type, YACA_KEY_1024BIT, &prv) != YACA_ERROR_NONE)
+ if (yaca_key_generate(type, YACA_KEY_LENGTH_1024BIT, &prv) != YACA_ERROR_NONE)
return;
if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE)
goto exit;
// SIGN
- if (yaca_sign(YACA_DIGEST_SHA512,
+ if (yaca_simple_calculate_signature(YACA_DIGEST_SHA512,
prv,
lorem4096,
LOREM4096_SIZE,
dump_hex(signature, signature_len, "[Simple API] %s Signature of lorem4096:", algo);
// VERIFY
- if (yaca_verify(YACA_DIGEST_SHA512,
+ if (yaca_simple_verify_signature(YACA_DIGEST_SHA512,
pub,
lorem4096,
LOREM4096_SIZE,
exit:
yaca_free(signature);
- yaca_key_free(prv);
- yaca_key_free(pub);
+ yaca_key_destroy(prv);
+ yaca_key_destroy(pub);
}
void simple_sign_verify_hmac(void)
yaca_key_h key = YACA_KEY_NULL;
// GENERATE
- if (yaca_key_gen(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT, &key) != YACA_ERROR_NONE)
+ if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key) != YACA_ERROR_NONE)
return;
// SIGN
- if (yaca_hmac(YACA_DIGEST_SHA512,
+ if (yaca_simple_calculate_hmac(YACA_DIGEST_SHA512,
key,
lorem4096,
LOREM4096_SIZE,
dump_hex(signature1, signature_len, "[Simple API] HMAC Signature of lorem4096:");
// VERIFY
- if (yaca_hmac(YACA_DIGEST_SHA512,
+ if (yaca_simple_calculate_hmac(YACA_DIGEST_SHA512,
key,
lorem4096,
LOREM4096_SIZE,
exit:
yaca_free(signature1);
yaca_free(signature2);
- yaca_key_free(key);
+ yaca_key_destroy(key);
}
void simple_sign_verify_cmac(void)
yaca_key_h key = YACA_KEY_NULL;
// GENERATE
- if (yaca_key_gen(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT, &key))
+ if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key))
return;
// SIGN
- if (yaca_cmac(YACA_ENC_AES,
+ if (yaca_simple_calculate_cmac(YACA_ENCRYPT_AES,
key,
lorem4096,
LOREM4096_SIZE,
// VERIFY
- if (yaca_cmac(YACA_ENC_AES,
+ if (yaca_simple_calculate_cmac(YACA_ENCRYPT_AES,
key,
lorem4096,
LOREM4096_SIZE,
exit:
yaca_free(signature1);
yaca_free(signature2);
- yaca_key_free(key);
+ yaca_key_destroy(key);
}
// Signature creation and verification using advanced API
char *signature = NULL;
size_t signature_len;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h prv = YACA_KEY_NULL;
yaca_key_h pub = YACA_KEY_NULL;
yaca_padding_e padding = YACA_PADDING_PKCS1_PSS;
// GENERATE
- if (yaca_key_gen(type, YACA_KEY_1024BIT, &prv) != YACA_ERROR_NONE)
+ if (yaca_key_generate(type, YACA_KEY_LENGTH_1024BIT, &prv) != YACA_ERROR_NONE)
return;
if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE)
goto exit;
// SIGN
- if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, prv) != YACA_ERROR_NONE)
+ if (yaca_sign_initialize(&ctx, YACA_DIGEST_SHA512, prv) != YACA_ERROR_NONE)
goto exit;
- if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE)
+ if (yaca_context_set_property(ctx, YACA_PROPERTY_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
if (yaca_malloc(signature_len, (void**)&signature) != YACA_ERROR_NONE)
goto exit;
- if (yaca_sign_final(ctx, signature, &signature_len) != YACA_ERROR_NONE)
+ if (yaca_sign_finalize(ctx, signature, &signature_len) != YACA_ERROR_NONE)
goto exit;
dump_hex(signature, signature_len, "[Advanced API] %s Signature of lorem4096:", algo);
// CLEANUP
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
// VERIFY
- if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, pub) != YACA_ERROR_NONE)
+ if (yaca_verify_initialize(&ctx, YACA_DIGEST_SHA512, pub) != YACA_ERROR_NONE)
goto exit;
- if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE)
+ if (yaca_context_set_property(ctx, YACA_PROPERTY_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE)
goto exit;
if (yaca_verify_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
goto exit;
- if (yaca_verify_final(ctx, signature, signature_len) != YACA_ERROR_NONE)
+ if (yaca_verify_finalize(ctx, signature, signature_len) != YACA_ERROR_NONE)
printf("[Advanced API] %s verification failed\n", algo);
else
printf("[Advanced API] %s verification successful\n", algo);
exit:
yaca_free(signature);
- yaca_key_free(prv);
- yaca_key_free(pub);
- yaca_ctx_free(ctx);
+ yaca_key_destroy(prv);
+ yaca_key_destroy(pub);
+ yaca_context_destroy(ctx);
}
void sign_verify_hmac(void)
char *signature2 = NULL;
size_t signature_len;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h key = YACA_KEY_NULL;
// GENERATE
- if (yaca_key_gen(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT, &key) != YACA_ERROR_NONE)
+ if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key) != YACA_ERROR_NONE)
return;
// SIGN
- if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE)
+ if (yaca_sign_initialize_hmac(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
if (yaca_malloc(signature_len, (void**)&signature1) != YACA_ERROR_NONE)
goto exit;
- if (yaca_sign_final(ctx, signature1, &signature_len) != YACA_ERROR_NONE)
+ if (yaca_sign_finalize(ctx, signature1, &signature_len) != YACA_ERROR_NONE)
goto exit;
dump_hex(signature1, signature_len, "[Advanced API] HMAC Signature of lorem4096:");
// CLEANUP
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
// VERIFY
- if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE)
+ if (yaca_sign_initialize_hmac(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE)
if (yaca_malloc(signature_len, (void**)&signature2) != YACA_ERROR_NONE)
goto exit;
- if (yaca_sign_final(ctx, signature2, &signature_len) != YACA_ERROR_NONE)
+ if (yaca_sign_finalize(ctx, signature2, &signature_len) != YACA_ERROR_NONE)
goto exit;
if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE)
exit:
yaca_free(signature1);
yaca_free(signature2);
- yaca_key_free(key);
- yaca_ctx_free(ctx);
+ yaca_key_destroy(key);
+ yaca_context_destroy(ctx);
}
void sign_verify_cmac(void)
char *signature2 = NULL;
size_t signature_len;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
yaca_key_h key = YACA_KEY_NULL;
// GENERATE
- if (yaca_key_gen(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT, &key))
+ if (yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_LENGTH_256BIT, &key))
return;
// SIGN
- if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != YACA_ERROR_NONE)
+ if (yaca_sign_initialize_cmac(&ctx, YACA_ENCRYPT_AES, key) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE))
if (yaca_malloc(signature_len, (void**)&signature1) != YACA_ERROR_NONE)
goto exit;
- if (yaca_sign_final(ctx, signature1, &signature_len))
+ if (yaca_sign_finalize(ctx, signature1, &signature_len))
goto exit;
dump_hex(signature1, signature_len, "[Advanced API] CMAC Signature of lorem4096:");
// CLEANUP
- yaca_ctx_free(ctx);
- ctx = YACA_CTX_NULL;
+ yaca_context_destroy(ctx);
+ ctx = YACA_CONTEXT_NULL;
// VERIFY
- if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != YACA_ERROR_NONE)
+ if (yaca_sign_initialize_cmac(&ctx, YACA_ENCRYPT_AES, key) != YACA_ERROR_NONE)
goto exit;
if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE))
if (yaca_malloc(signature_len, (void**)&signature2) != YACA_ERROR_NONE)
goto exit;
- if (yaca_sign_final(ctx, signature2, &signature_len))
+ if (yaca_sign_finalize(ctx, signature2, &signature_len))
goto exit;
if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE)
exit:
yaca_free(signature1);
yaca_free(signature2);
- yaca_key_free(key);
- yaca_ctx_free(ctx);
+ yaca_key_destroy(key);
+ yaca_context_destroy(ctx);
}
int main()
{
yaca_debug_set_error_cb(debug_func);
- int ret = yaca_init();
+ int ret = yaca_initialize();
if (ret != YACA_ERROR_NONE)
return ret;
sign_verify_hmac();
sign_verify_cmac();
- yaca_exit();
+ yaca_cleanup();
return ret;
}
}
}
-API int yaca_init(void)
+API int yaca_initialize(void)
{
int ret;
if (mutexes != NULL)
return YACA_ERROR_NONE;
}
-API int yaca_exit(void)
+API int yaca_cleanup(void)
{
ERR_free_strings();
ERR_remove_thread_state(NULL);
API int yaca_malloc(size_t size, void **memory)
{
if (size == 0 || memory == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
*memory = OPENSSL_malloc(size);
if (*memory == NULL) {
API int yaca_realloc(size_t size, void **memory)
{
if (size == 0 || memory == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
void *tmp = OPENSSL_realloc(*memory, size);
if (tmp == NULL) {
return YACA_ERROR_NONE;
}
-API int yaca_rand_bytes(char *data, size_t data_len)
+API int yaca_randomize_bytes(char *data, size_t data_len)
{
int ret;
if (data == NULL || data_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = RAND_bytes((unsigned char *)data, data_len);
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param,
- const void *value, size_t value_len)
+API int yaca_context_set_property(yaca_context_h ctx, yaca_property_e param,
+ const void *value, size_t value_len)
{
- if (ctx == YACA_CTX_NULL || ctx->set_param == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ if (ctx == YACA_CONTEXT_NULL || ctx->set_param == NULL)
+ return YACA_ERROR_INVALID_PARAMETER;
return ctx->set_param(ctx, param, value, value_len);
}
-API int yaca_ctx_get_param(const yaca_ctx_h ctx, yaca_ex_param_e param,
- void **value, size_t *value_len)
+API int yaca_context_get_property(const yaca_context_h ctx, yaca_property_e param,
+ void **value, size_t *value_len)
{
- if (ctx == YACA_CTX_NULL || ctx->get_param == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ if (ctx == YACA_CONTEXT_NULL || ctx->get_param == NULL)
+ return YACA_ERROR_INVALID_PARAMETER;
return ctx->get_param(ctx, param, value, value_len);
}
-API int yaca_ctx_free(yaca_ctx_h ctx)
+API int yaca_context_destroy(yaca_context_h ctx)
{
- if (ctx != YACA_CTX_NULL) {
+ if (ctx != YACA_CONTEXT_NULL) {
assert(ctx->ctx_destroy != NULL);
ctx->ctx_destroy(ctx);
yaca_free(ctx);
return YACA_ERROR_NONE;
}
-API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len)
+API int yaca_get_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len)
{
- if (ctx == YACA_CTX_NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ if (ctx == YACA_CONTEXT_NULL)
+ return YACA_ERROR_INVALID_PARAMETER;
return ctx->get_output_length(ctx, input_len, output_len);
}
switch (err) {
case YACA_ERROR_NONE:
return "YACA_ERROR_NONE";
- case YACA_ERROR_INVALID_ARGUMENT:
- return "YACA_ERROR_INVALID_ARGUMENT";
+ case YACA_ERROR_INVALID_PARAMETER:
+ return "YACA_ERROR_INVALID_PARAMETER";
case YACA_ERROR_OUT_OF_MEMORY:
return "YACA_ERROR_OUT_OF_MEMORY";
case YACA_ERROR_INTERNAL:
return "YACA_ERROR_INTERNAL";
case YACA_ERROR_DATA_MISMATCH:
return "YACA_ERROR_DATA_MISMATCH";
- case YACA_ERROR_PASSWORD_INVALID:
- return "YACA_ERROR_PASSWORD_INVALID";
+ case YACA_ERROR_INVALID_PASSWORD:
+ return "YACA_ERROR_INVALID_PASSWORD";
default:
return NULL;
}
break;
case ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED:
case ERR_R_PASSED_NULL_PARAMETER:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
break;
case ERR_R_INTERNAL_ERROR:
case ERR_R_DISABLED:
switch (err) {
case ERR_PACK(ERR_LIB_RSA, RSA_F_PKEY_RSA_CTRL, RSA_R_INVALID_KEYBITS):
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_PKEY_CTX_CTRL, EVP_R_COMMAND_NOT_SUPPORTED):
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
break;
case ERR_PACK(ERR_LIB_PEM, PEM_F_PEM_DO_HEADER, PEM_R_BAD_DECRYPT):
case ERR_PACK(ERR_LIB_EVP, EVP_F_EVP_DECRYPTFINAL_EX, EVP_R_BAD_DECRYPT):
- ret = YACA_ERROR_PASSWORD_INVALID;
+ ret = YACA_ERROR_INVALID_PASSWORD;
break;
default:
error_dump(file, line, function, YACA_ERROR_INTERNAL);
#include "internal.h"
struct yaca_digest_ctx_s {
- struct yaca_ctx_s ctx;
+ struct yaca_context_s ctx;
EVP_MD_CTX *mdctx;
};
-static struct yaca_digest_ctx_s *get_digest_ctx(const yaca_ctx_h ctx)
+static struct yaca_digest_ctx_s *get_digest_ctx(const yaca_context_h ctx)
{
- if (ctx == YACA_CTX_NULL)
+ if (ctx == YACA_CONTEXT_NULL)
return NULL;
switch (ctx->type) {
}
}
-static int get_digest_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len)
+static int get_digest_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len)
{
struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
if (c == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
int md_size = EVP_MD_CTX_size(c->mdctx);
if (md_size <= 0)
return YACA_ERROR_NONE;
}
-static void destroy_digest_context(yaca_ctx_h ctx)
+static void destroy_digest_context(yaca_context_h ctx)
{
struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
c->mdctx = NULL;
}
-int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md)
+int digest_get_algorithm(yaca_digest_algorithm_e algo, const EVP_MD **md)
{
int ret = YACA_ERROR_NONE;
if (!md)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
*md = NULL;
*md = EVP_sha512();
break;
default:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
break;
}
return ret;
}
-API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo)
+API int yaca_digest_initialize(yaca_context_h *ctx, yaca_digest_algorithm_e algo)
{
int ret;
struct yaca_digest_ctx_s *nc = NULL;
const EVP_MD *md;
if (ctx == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_digest_ctx_s), (void**)&nc);
if (ret != YACA_ERROR_NONE)
goto exit;
}
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-API int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len)
+API int yaca_digest_update(yaca_context_h ctx, const char *data, size_t data_len)
{
struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
int ret;
if (c == NULL || data == NULL || data_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestUpdate(c->mdctx, data, data_len);
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len)
+API int yaca_digest_finalize(yaca_context_h ctx, char *digest, size_t *digest_len)
{
struct yaca_digest_ctx_s *c = get_digest_ctx(ctx);
int ret;
unsigned len = 0;
if (c == NULL || digest == NULL || digest_len == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (*digest_len == 0 || *digest_len > UINT_MAX) // DigestFinal accepts uint
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestFinal_ex(c->mdctx, (unsigned char*)digest, &len);
if (ret != 1) {
};
struct yaca_encrypt_ctx_s {
- struct yaca_ctx_s ctx;
+ struct yaca_context_s ctx;
EVP_CIPHER_CTX *cipher_ctx;
enum encrypt_op_type op_type; /* Operation context was created for */
size_t tag_len;
};
-static struct yaca_encrypt_ctx_s *get_encrypt_ctx(const yaca_ctx_h ctx)
+static struct yaca_encrypt_ctx_s *get_encrypt_ctx(const yaca_context_h ctx)
{
- if (ctx == YACA_CTX_NULL)
+ if (ctx == YACA_CONTEXT_NULL)
return NULL;
switch (ctx->type) {
}
}
-static void destroy_encrypt_ctx(const yaca_ctx_h ctx)
+static void destroy_encrypt_ctx(const yaca_context_h ctx)
{
struct yaca_encrypt_ctx_s *nc = get_encrypt_ctx(ctx);
nc->cipher_ctx = NULL;
}
-static int get_encrypt_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len)
+static int get_encrypt_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len)
{
struct yaca_encrypt_ctx_s *nc = get_encrypt_ctx(ctx);
int block_size;
if (nc == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(nc->cipher_ctx != NULL);
block_size = EVP_CIPHER_CTX_block_size(nc->cipher_ctx);
if (input_len > 0) {
if ((size_t)block_size > SIZE_MAX - input_len + 1)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
*output_len = block_size + input_len - 1;
} else {
return YACA_ERROR_NONE;
}
-static int set_encrypt_param(yaca_ctx_h ctx,
- yaca_ex_param_e param,
+static int set_encrypt_param(yaca_context_h ctx,
+ yaca_property_e param,
const void *value,
size_t value_len)
{
int len;
if (c == NULL || value == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(c->cipher_ctx != NULL);
switch (param) {
- case YACA_PARAM_GCM_AAD:
- case YACA_PARAM_CCM_AAD:
+ case YACA_PROPERTY_GCM_AAD:
+ case YACA_PROPERTY_CCM_AAD:
if (EVP_EncryptUpdate(c->cipher_ctx, NULL, &len, value, value_len) != 1) {
ERROR_DUMP(YACA_ERROR_INTERNAL);
return YACA_ERROR_INTERNAL;
}
break;
- case YACA_PARAM_GCM_TAG:
+ case YACA_PROPERTY_GCM_TAG:
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_GCM_SET_TAG,
value_len, (void*)value) != 1) {
return YACA_ERROR_INTERNAL;
}
break;
- case YACA_PARAM_GCM_TAG_LEN:
+ case YACA_PROPERTY_GCM_TAG_LEN:
c->tag_len = *(int*)value;
break;
- case YACA_PARAM_CCM_TAG:
+ case YACA_PROPERTY_CCM_TAG:
// TODO Rebuild context
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_CCM_SET_TAG,
return YACA_ERROR_INTERNAL;
}
break;
- case YACA_PARAM_CCM_TAG_LEN:
+ case YACA_PROPERTY_CCM_TAG_LEN:
//TODO Rebuild context
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_CCM_SET_TAG,
c->tag_len = *(int*)value;
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
return YACA_ERROR_NONE;
}
-static int get_encrypt_param(const yaca_ctx_h ctx,
- yaca_ex_param_e param,
+static int get_encrypt_param(const yaca_context_h ctx,
+ yaca_property_e param,
void **value,
size_t *value_len)
{
struct yaca_encrypt_ctx_s *c = get_encrypt_ctx(ctx);
if (c == NULL || value == NULL || value_len == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(c->cipher_ctx != NULL);
switch (param) {
- case YACA_PARAM_GCM_TAG:
+ case YACA_PROPERTY_GCM_TAG:
if (c->tag_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_GCM_GET_TAG,
}
*value_len = c->tag_len;
break;
- case YACA_PARAM_CCM_TAG:
+ case YACA_PROPERTY_CCM_TAG:
if (c->tag_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
EVP_CTRL_CCM_GET_TAG,
*value_len = c->tag_len;
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
break;
}
return YACA_ERROR_NONE;
}
-static const char *encrypt_algo_to_str(yaca_enc_algo_e algo)
+static const char *encrypt_algo_to_str(yaca_encrypt_algorithm_e algo)
{
switch (algo) {
- case YACA_ENC_AES:
+ case YACA_ENCRYPT_AES:
return "aes";
- case YACA_ENC_UNSAFE_DES:
+ case YACA_ENCRYPT_UNSAFE_DES:
return "des";
- case YACA_ENC_UNSAFE_3DES_2TDEA:
+ case YACA_ENCRYPT_UNSAFE_3DES_2TDEA:
return "des-ede";
- case YACA_ENC_3DES_3TDEA:
+ case YACA_ENCRYPT_3DES_3TDEA:
return "des-ede3";
- case YACA_ENC_UNSAFE_RC2:
+ case YACA_ENCRYPT_UNSAFE_RC2:
return "rc2";
- case YACA_ENC_UNSAFE_RC4:
+ case YACA_ENCRYPT_UNSAFE_RC4:
return "rc4";
- case YACA_ENC_CAST5:
+ case YACA_ENCRYPT_CAST5:
return "cast5";
default:
return NULL;
}
}
-int encrypt_get_algorithm(yaca_enc_algo_e algo,
+int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
yaca_block_cipher_mode_e bcm,
size_t key_bits,
const EVP_CIPHER **cipher)
if (algo_name == NULL || bcm_name == NULL || key_bits == 0 ||
cipher == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (algo) {
- case YACA_ENC_AES:
+ case YACA_ENCRYPT_AES:
ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%zu-%s",
algo_name, key_bits, bcm_name);
break;
- case YACA_ENC_UNSAFE_DES:
- case YACA_ENC_UNSAFE_RC2:
- case YACA_ENC_CAST5:
+ case YACA_ENCRYPT_UNSAFE_DES:
+ case YACA_ENCRYPT_UNSAFE_RC2:
+ case YACA_ENCRYPT_CAST5:
ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%s",
algo_name, bcm_name);
break;
- case YACA_ENC_UNSAFE_3DES_2TDEA:
- case YACA_ENC_3DES_3TDEA:
+ case YACA_ENCRYPT_UNSAFE_3DES_2TDEA:
+ case YACA_ENCRYPT_3DES_3TDEA:
if (bcm == YACA_BCM_ECB)
ret = snprintf(cipher_name, sizeof(cipher_name), "%s", algo_name);
else
ret = snprintf(cipher_name, sizeof(cipher_name), "%s-%s",
algo_name, bcm_name);
break;
- case YACA_ENC_UNSAFE_RC4:
+ case YACA_ENCRYPT_UNSAFE_RC4:
ret = snprintf(cipher_name, sizeof(cipher_name), "%s", algo_name);
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret < 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if ((unsigned)ret >= sizeof(cipher_name)) // output was truncated
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
lcipher = EVP_get_cipherbyname(cipher_name);
if (lcipher == NULL) {
return YACA_ERROR_NONE;
}
-static int encrypt_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
+static int encrypt_init(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
yaca_block_cipher_mode_e bcm,
const yaca_key_h sym_key,
const yaca_key_h iv,
int ret;
if (ctx == NULL || sym_key == YACA_KEY_NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
lkey = key_get_simple(sym_key);
if (lkey == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_encrypt_ctx_s), (void**)&nc);
if (ret != YACA_ERROR_NONE)
nc->op_type = op_type;
nc->tag_len = 0;
- ret = yaca_key_get_bits(sym_key, &key_bits);
+ ret = yaca_key_get_bit_length(sym_key, &key_bits);
if (ret != YACA_ERROR_NONE)
goto exit;
iv_bits = ret * 8;
if (iv_bits == 0 && iv != NULL) { /* 0 -> cipher doesn't use iv, but it was provided */
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
if (iv_bits != 0) { /* cipher requires iv*/
liv = key_get_simple(iv);
if (liv == NULL) { /* iv was not provided */
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
- ret = yaca_key_get_bits(iv, &iv_bits_check);
+ ret = yaca_key_get_bit_length(iv, &iv_bits_check);
if (ret != YACA_ERROR_NONE) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
/* IV length doesn't match cipher (GCM & CCM supports variable IV length) */
if (iv_bits != iv_bits_check &&
bcm != YACA_BCM_GCM &&
bcm != YACA_BCM_CCM) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
iv_data = (unsigned char*)liv->d;
ret = EVP_DecryptInit_ex(nc->cipher_ctx, cipher, NULL, NULL, NULL);
break;
default:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
/* Handling of algorithms with variable key length */
ret = EVP_CIPHER_CTX_set_key_length(nc->cipher_ctx, key_bits / 8);
if (ret != 1) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
ERROR_DUMP(ret);
goto exit;
}
iv_bits_check / 8, NULL);
if (ret != 1) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
ERROR_DUMP(ret);
goto exit;
}
iv_data);
break;
default:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
goto exit;
}
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-static int encrypt_update(yaca_ctx_h ctx,
+static int encrypt_update(yaca_context_h ctx,
const unsigned char *input,
size_t input_len,
unsigned char *output,
int loutput_len;
if (c == NULL || input_len == 0 || output_len == NULL || op_type != c->op_type)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
loutput_len = *output_len;
input, input_len);
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret != 1) {
return YACA_ERROR_NONE;
}
-static int encrypt_final(yaca_ctx_h ctx,
+static int encrypt_final(yaca_context_h ctx,
unsigned char *output,
size_t *output_len,
enum encrypt_op_type op_type)
if (c == NULL || output == NULL || output_len == NULL ||
op_type != c->op_type)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
loutput_len = *output_len;
ret = EVP_DecryptFinal(c->cipher_ctx, output, &loutput_len);
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_get_iv_bits(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bits,
- size_t *iv_bits)
+API int yaca_encrypt_get_iv_bit_length(yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bits,
+ size_t *iv_bits)
{
const EVP_CIPHER *cipher;
int ret;
return YACA_ERROR_NONE;
}
-API int yaca_encrypt_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+API int yaca_encrypt_initialize(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
return encrypt_init(ctx, algo, bcm, sym_key, iv, OP_ENCRYPT);
}
-API int yaca_encrypt_update(yaca_ctx_h ctx,
+API int yaca_encrypt_update(yaca_context_h ctx,
const char *plain,
size_t plain_len,
char *cipher,
(unsigned char*)cipher, cipher_len, OP_ENCRYPT);
}
-API int yaca_encrypt_final(yaca_ctx_h ctx,
- char *cipher,
- size_t *cipher_len)
+API int yaca_encrypt_finalize(yaca_context_h ctx,
+ char *cipher,
+ size_t *cipher_len)
{
return encrypt_final(ctx, (unsigned char*)cipher,
cipher_len, OP_ENCRYPT);
}
-API int yaca_decrypt_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+API int yaca_decrypt_initialize(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
return encrypt_init(ctx, algo, bcm, sym_key, iv, OP_DECRYPT);
}
-API int yaca_decrypt_update(yaca_ctx_h ctx,
+API int yaca_decrypt_update(yaca_context_h ctx,
const char *cipher,
size_t cipher_len,
char *plain,
(unsigned char*)plain, plain_len, OP_DECRYPT);
}
-API int yaca_decrypt_final(yaca_ctx_h ctx,
- char *plain,
- size_t *plain_len)
+API int yaca_decrypt_finalize(yaca_context_h ctx,
+ char *plain,
+ size_t *plain_len)
{
return encrypt_final(ctx, (unsigned char*)plain, plain_len,
OP_DECRYPT);
};
/* Base structure for crypto contexts - to be inherited */
-struct yaca_ctx_s {
+struct yaca_context_s {
enum yaca_ctx_type_e type;
- void (*ctx_destroy)(const yaca_ctx_h ctx);
- int (*get_output_length)(const yaca_ctx_h ctx, size_t input_len, size_t *output_len);
- int (*set_param)(yaca_ctx_h ctx, yaca_ex_param_e param,
+ void (*ctx_destroy)(const yaca_context_h ctx);
+ int (*get_output_length)(const yaca_context_h ctx, size_t input_len, size_t *output_len);
+ int (*set_param)(yaca_context_h ctx, yaca_property_e param,
const void *value, size_t value_len);
- int (*get_param)(const yaca_ctx_h ctx, yaca_ex_param_e param,
+ int (*get_param)(const yaca_context_h ctx, yaca_property_e param,
void **value, size_t *value_len);
};
EVP_PKEY *evp;
};
-int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md);
+int digest_get_algorithm(yaca_digest_algorithm_e algo, const EVP_MD **md);
-int encrypt_get_algorithm(yaca_enc_algo_e algo,
+int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
yaca_block_cipher_mode_e bcm,
size_t key_bits,
const EVP_CIPHER **cipher);
size_t tmp_len = data_len;
if (data_len % 4 != 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (data[tmp_len - 1] == '=') {
padded = 1;
/* This is because of BIO_new_mem_buf() having its length param typed int */
if (data_len > INT_MAX)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
/* First phase of correctness checking, calculate expected output length */
ret = base64_decode_length(data, data_len, &b64_len);
goto exit;
}
if ((size_t)out_len != b64_len) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
return ret;
}
key_data_len = len;
- } else if (ret == YACA_ERROR_INVALID_ARGUMENT) {
+ } else if (ret == YACA_ERROR_INVALID_PARAMETER) {
/* This was not BASE64 or it was corrupted, treat as RAW */
key_data_len = data_len;
key_data = data;
/* key_bits has to fit in size_t */
if (key_data_len > SIZE_MAX / 8) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
/* DES key length verification */
if (key_type == YACA_KEY_TYPE_DES) {
size_t key_bits = key_data_len * 8;
- if (key_bits != YACA_KEY_UNSAFE_64BIT &&
- key_bits != YACA_KEY_UNSAFE_128BIT &&
- key_bits != YACA_KEY_192BIT) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ if (key_bits != YACA_KEY_LENGTH_UNSAFE_64BIT &&
+ key_bits != YACA_KEY_LENGTH_UNSAFE_128BIT &&
+ key_bits != YACA_KEY_LENGTH_192BIT) {
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
}
* sure we have at least 4 bytes for strncmp() below.
*/
if (data_len < 4)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
/* This is because of BIO_new_mem_buf() having its length param typed int */
if (data_len > INT_MAX)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
src = BIO_new_mem_buf(data, data_len);
if (src == NULL) {
BIO_free(src);
if (wrong_pass)
- return YACA_ERROR_PASSWORD_INVALID;
+ return YACA_ERROR_INVALID_PASSWORD;
if (pkey == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (EVP_PKEY_type(pkey->type)) {
case EVP_PKEY_RSA:
// break;
default:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
if (type != key_type) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
}
int export_evp_default_bio(struct yaca_key_evp_s *evp_key,
- yaca_key_file_fmt_e key_file_fmt,
+ yaca_key_file_format_e key_file_fmt,
const char *password,
BIO *mem)
{
// case YACA_KEY_TYPE_EC_PUB:
// TODO NOT_IMPLEMENTED
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
break;
// case YACA_KEY_TYPE_EC_PUB:
// TODO NOT_IMPLEMENTED
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret <= 0) {
}
int export_evp_pkcs8_bio(struct yaca_key_evp_s *evp_key,
- yaca_key_file_fmt_e key_file_fmt,
+ yaca_key_file_format_e key_file_fmt,
const char *password,
BIO *mem)
{
// TODO NOT_IMPLEMENTED
default:
/* Public keys are not supported by PKCS8 */
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
break;
// TODO NOT_IMPLEMENTED
default:
/* Public keys are not supported by PKCS8 */
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret <= 0) {
}
int export_evp(struct yaca_key_evp_s *evp_key,
- yaca_key_fmt_e key_fmt,
- yaca_key_file_fmt_e key_file_fmt,
+ yaca_key_format_e key_fmt,
+ yaca_key_file_format_e key_file_fmt,
const char *password,
char **data,
size_t *data_len)
ret = export_evp_pkcs8_bio(evp_key, key_file_fmt, password, mem);
break;
default:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
break;
}
nk->bits = key_bits;
- ret = yaca_rand_bytes(nk->d, key_byte_len);
+ ret = yaca_randomize_bytes(nk->d, key_byte_len);
if (ret != YACA_ERROR_NONE)
return ret;
{
assert(out != NULL);
- if (key_bits != YACA_KEY_UNSAFE_64BIT &&
- key_bits != YACA_KEY_UNSAFE_128BIT &&
- key_bits != YACA_KEY_192BIT)
- return YACA_ERROR_INVALID_ARGUMENT;
+ if (key_bits != YACA_KEY_LENGTH_UNSAFE_64BIT &&
+ key_bits != YACA_KEY_LENGTH_UNSAFE_128BIT &&
+ key_bits != YACA_KEY_LENGTH_192BIT)
+ return YACA_ERROR_INVALID_PARAMETER;
int ret;
struct yaca_key_simple_s *nk;
/* Openssl generates 512-bit key for key lengths smaller than 512. It also
* rounds key size to multiplication of 64. */
if(key_bits < 512 || key_bits % 64 != 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
int ret;
struct yaca_key_evp_s *nk;
const struct yaca_key_s *lkey = (const struct yaca_key_s *)key;
if (lkey == NULL || key_type == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
*key_type = lkey->type;
return YACA_ERROR_NONE;
}
-API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits)
+API int yaca_key_get_bit_length(const yaca_key_h key, size_t *key_bits)
{
const struct yaca_key_simple_s *simple_key = key_get_simple(key);
const struct yaca_key_evp_s *evp_key = key_get_evp(key);
if (key_bits == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (simple_key != NULL) {
*key_bits = simple_key->bits;
return YACA_ERROR_NONE;
}
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
API int yaca_key_import(yaca_key_type_e key_type,
yaca_key_h *key)
{
if (key == NULL || data == NULL || data_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
/* allow an empty password, OpenSSL returns an error with "" */
if (password != NULL && password[0] == '\0')
case YACA_KEY_TYPE_DES:
case YACA_KEY_TYPE_IV:
if (password != NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
return import_simple(key, key_type, data, data_len);
case YACA_KEY_TYPE_RSA_PUB:
case YACA_KEY_TYPE_RSA_PRIV:
// case YACA_KEY_TYPE_EC_PRIV:
// TODO NOT_IMPLEMENTED
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
}
API int yaca_key_export(const yaca_key_h key,
- yaca_key_fmt_e key_fmt,
- yaca_key_file_fmt_e key_file_fmt,
+ yaca_key_format_e key_fmt,
+ yaca_key_file_format_e key_file_fmt,
const char *password,
char **data,
size_t *data_len)
struct yaca_key_evp_s *evp_key = key_get_evp(key);
if (data == NULL || data_len == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
/* allow an empty password, OpenSSL returns an error with "" */
if (password != NULL && password[0] == '\0')
password = NULL;
if (password != NULL && simple_key != NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (key_fmt == YACA_KEY_FORMAT_DEFAULT &&
key_file_fmt == YACA_KEY_FILE_FORMAT_RAW &&
return export_evp(evp_key, key_fmt, key_file_fmt,
password, data, data_len);
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
-API int yaca_key_gen(yaca_key_type_e key_type,
- size_t key_bits,
- yaca_key_h *key)
+API int yaca_key_generate(yaca_key_type_e key_type,
+ size_t key_bits,
+ yaca_key_h *key)
{
int ret;
struct yaca_key_simple_s *nk_simple = NULL;
struct yaca_key_evp_s *nk_evp = NULL;
if (key == NULL || key_bits == 0 || key_bits % 8 != 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (key_type) {
case YACA_KEY_TYPE_SYMMETRIC:
// case YACA_KEY_TYPE_EC_PRIV:
// TODO NOT_IMPLEMENTED
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret != YACA_ERROR_NONE)
EVP_PKEY *pkey = NULL;
if (prv_key == YACA_KEY_NULL || evp_key == NULL || pub_key == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_key_evp_s), (void**)&nk);
if (ret != YACA_ERROR_NONE)
// nk->key.type = YACA_KEY_TYPE_EC_PUB;
// break;
default:
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
return ret;
}
-API int yaca_key_free(yaca_key_h key)
+API int yaca_key_destroy(yaca_key_h key)
{
struct yaca_key_simple_s *simple_key = key_get_simple(key);
struct yaca_key_evp_s *evp_key = key_get_evp(key);
const char *salt,
size_t salt_len,
int iter,
- yaca_digest_algo_e algo,
+ yaca_digest_algorithm_e algo,
size_t key_bits,
yaca_key_h *key)
{
if (password == NULL || salt == NULL || salt_len == 0 ||
iter == 0 || key_bits == 0 || key == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (key_bits % 8) /* Key length must be multiple of 8-bits */
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = digest_get_algorithm(algo, &md);
if (ret != YACA_ERROR_NONE)
};
struct yaca_seal_ctx_s {
- struct yaca_ctx_s ctx;
+ struct yaca_context_s ctx;
EVP_CIPHER_CTX *cipher_ctx;
enum seal_op_type op_type; /* Operation context was created for */
};
-static struct yaca_seal_ctx_s *get_seal_ctx(const yaca_ctx_h ctx)
+static struct yaca_seal_ctx_s *get_seal_ctx(const yaca_context_h ctx)
{
- if (ctx == YACA_CTX_NULL)
+ if (ctx == YACA_CONTEXT_NULL)
return NULL;
switch (ctx->type) {
}
}
-static void destroy_seal_ctx(const yaca_ctx_h ctx)
+static void destroy_seal_ctx(const yaca_context_h ctx)
{
struct yaca_seal_ctx_s *nc = get_seal_ctx(ctx);
nc->cipher_ctx = NULL;
}
-static int get_seal_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len)
+static int get_seal_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len)
{
struct yaca_seal_ctx_s *nc = get_seal_ctx(ctx);
int block_size;
if (nc == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(nc->cipher_ctx);
block_size = EVP_CIPHER_CTX_block_size(nc->cipher_ctx);
if (input_len > 0) {
if ((size_t)block_size > SIZE_MAX - input_len + 1)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
*output_len = block_size + input_len - 1;
} else {
return YACA_ERROR_NONE;
}
-static int seal_init(yaca_ctx_h *ctx,
+static int seal_init(yaca_context_h *ctx,
const yaca_key_h pub_key,
- yaca_enc_algo_e algo,
+ yaca_encrypt_algorithm_e algo,
yaca_block_cipher_mode_e bcm,
- yaca_key_bits_e sym_key_bits,
+ yaca_key_bit_length_e sym_key_bits,
yaca_key_h *sym_key,
yaca_key_h *iv)
{
int ret;
if (ctx == NULL || pub_key == YACA_KEY_NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (pub_key->type != YACA_KEY_TYPE_RSA_PUB)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
lpub = key_get_evp(pub_key);
assert(lpub);
} else {
*iv = NULL;
}
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
yaca_free(liv);
yaca_free(lkey);
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-static int open_init(yaca_ctx_h *ctx,
+static int open_init(yaca_context_h *ctx,
const yaca_key_h prv_key,
- yaca_enc_algo_e algo,
+ yaca_encrypt_algorithm_e algo,
yaca_block_cipher_mode_e bcm,
- yaca_key_bits_e sym_key_bits,
+ yaca_key_bit_length_e sym_key_bits,
const yaca_key_h sym_key,
const yaca_key_h iv)
{
int ret;
if (ctx == NULL || prv_key == YACA_KEY_NULL || sym_key == YACA_KEY_NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
if (prv_key->type != YACA_KEY_TYPE_RSA_PRIV)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
lprv = key_get_evp(prv_key);
assert(lprv);
lkey = key_get_simple(sym_key);
if (lkey == NULL || lkey->key.type != YACA_KEY_TYPE_SYMMETRIC)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_seal_ctx_s), (void**)&nc);
if (ret != YACA_ERROR_NONE)
iv_bits = ret * 8;
if (iv_bits == 0 && iv != NULL) { /* 0 -> cipher doesn't use iv, but it was provided */
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
if (iv_bits > 0) { /* cipher requires iv*/
liv = key_get_simple(iv);
if (liv == NULL || liv->key.type != YACA_KEY_TYPE_IV) { /* iv was not provided */
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
- ret = yaca_key_get_bits(iv, &iv_bits_check);
+ ret = yaca_key_get_bit_length(iv, &iv_bits_check);
if (ret != YACA_ERROR_NONE) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
/* IV length doesn't match cipher */
if (iv_bits != iv_bits_check) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
iv_data = (unsigned char*)liv->d;
goto exit;
}
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-static int seal_update(yaca_ctx_h ctx,
+static int seal_update(yaca_context_h ctx,
const unsigned char *input,
size_t input_len,
unsigned char *output,
if (c == NULL || input == NULL || input_len == 0 ||
output == NULL || output_len == NULL || op_type != c->op_type)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (op_type) {
case OP_SEAL:
ret = EVP_OpenUpdate(c->cipher_ctx, output, (int*)output_len, input, input_len);
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret != 1) {
return YACA_ERROR_NONE;
}
-static int seal_final(yaca_ctx_h ctx,
+static int seal_final(yaca_context_h ctx,
unsigned char *output,
size_t *output_len,
enum seal_op_type op_type)
int ret;
if (c == NULL || output == NULL || output_len == NULL || op_type != c->op_type)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (op_type) {
case OP_SEAL:
ret = EVP_OpenFinal(c->cipher_ctx, output, (int*)output_len);
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_seal_init(yaca_ctx_h *ctx,
- const yaca_key_h pub_key,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- yaca_key_bits_e sym_key_bits,
- yaca_key_h *sym_key,
- yaca_key_h *iv)
+API int yaca_seal_initialize(yaca_context_h *ctx,
+ const yaca_key_h pub_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ yaca_key_bit_length_e sym_key_bits,
+ yaca_key_h *sym_key,
+ yaca_key_h *iv)
{
return seal_init(ctx, pub_key, algo, bcm, sym_key_bits, sym_key, iv);
}
-API int yaca_seal_update(yaca_ctx_h ctx,
+API int yaca_seal_update(yaca_context_h ctx,
const char *plain,
size_t plain_len,
char *cipher,
OP_SEAL);
}
-API int yaca_seal_final(yaca_ctx_h ctx,
- char *cipher,
- size_t *cipher_len)
+API int yaca_seal_finalize(yaca_context_h ctx,
+ char *cipher,
+ size_t *cipher_len)
{
return seal_final(ctx,
(unsigned char*)cipher,
OP_SEAL);
}
-API int yaca_open_init(yaca_ctx_h *ctx,
- const yaca_key_h prv_key,
- yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- yaca_key_bits_e sym_key_bits,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+API int yaca_open_initialize(yaca_context_h *ctx,
+ const yaca_key_h prv_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ yaca_key_bit_length_e sym_key_bits,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
return open_init(ctx, prv_key, algo, bcm, sym_key_bits, sym_key, iv);
}
-API int yaca_open_update(yaca_ctx_h ctx,
+API int yaca_open_update(yaca_context_h ctx,
const char *cipher,
size_t cipher_len,
char *plain,
OP_OPEN);
}
-API int yaca_open_final(yaca_ctx_h ctx,
- char *plain,
- size_t *plain_len)
+API int yaca_open_finalize(yaca_context_h ctx,
+ char *plain,
+ size_t *plain_len)
{
return seal_final(ctx, (unsigned char*)plain, plain_len, OP_OPEN);
}
};
struct yaca_sign_ctx_s {
- struct yaca_ctx_s ctx;
+ struct yaca_context_s ctx;
EVP_MD_CTX *mdctx;
enum sign_op_type op_type;
};
-static struct yaca_sign_ctx_s *get_sign_ctx(const yaca_ctx_h ctx)
+static struct yaca_sign_ctx_s *get_sign_ctx(const yaca_context_h ctx)
{
- if (ctx == YACA_CTX_NULL)
+ if (ctx == YACA_CONTEXT_NULL)
return NULL;
switch (ctx->type) {
}
}
-static int get_sign_output_length(const yaca_ctx_h ctx,
+static int get_sign_output_length(const yaca_context_h ctx,
size_t input_len,
size_t *output_len)
{
struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
if (c == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(c->mdctx != NULL);
return YACA_ERROR_NONE;
}
-static void destroy_sign_context(yaca_ctx_h ctx)
+static void destroy_sign_context(yaca_context_h ctx)
{
struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
c->mdctx = NULL;
}
-int set_sign_param(yaca_ctx_h ctx,
- yaca_ex_param_e param,
+int set_sign_param(yaca_context_h ctx,
+ yaca_property_e param,
const void *value,
size_t value_len)
{
EVP_PKEY *pkey;
if (c == NULL || value == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(c->mdctx != NULL);
return YACA_ERROR_INTERNAL;
/* this function only supports padding */
- if (param != YACA_PARAM_PADDING || value_len != sizeof(yaca_padding_e))
- return YACA_ERROR_INVALID_ARGUMENT;
+ if (param != YACA_PROPERTY_PADDING || value_len != sizeof(yaca_padding_e))
+ return YACA_ERROR_INVALID_PARAMETER;
padding = *(yaca_padding_e *)(value);
pad = RSA_PKCS1_PSS_PADDING;
break;
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
pkey = EVP_PKEY_CTX_get0_pkey(c->mdctx->pctx);
/* padding only works for RSA */
if (pkey->type != EVP_PKEY_RSA)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_PKEY_CTX_set_rsa_padding(c->mdctx->pctx, pad);
if (ret <= 0) {
return YACA_ERROR_NONE;
}
-int get_sign_param(const yaca_ctx_h ctx,
- yaca_ex_param_e param,
+int get_sign_param(const yaca_context_h ctx,
+ yaca_property_e param,
void **value,
size_t *value_len)
{
yaca_padding_e padding;
if (c == NULL || value == NULL || value_len == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
assert(c->mdctx != NULL);
return YACA_ERROR_INTERNAL;
/* this function only supports padding */
- if (param != YACA_PARAM_PADDING)
- return YACA_ERROR_INVALID_ARGUMENT;
+ if (param != YACA_PROPERTY_PADDING)
+ return YACA_ERROR_INVALID_PARAMETER;
pkey = EVP_PKEY_CTX_get0_pkey(c->mdctx->pctx);
if (pkey == NULL) {
/* padding only works for RSA */
if (pkey->type != EVP_PKEY_RSA)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_PKEY_CTX_get_rsa_padding(c->mdctx->pctx, &pad);
if (ret <= 0) {
return YACA_ERROR_NONE;
}
-API int yaca_sign_init(yaca_ctx_h *ctx,
- yaca_digest_algo_e algo,
- const yaca_key_h key)
+API int yaca_sign_initialize(yaca_context_h *ctx,
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h key)
{
struct yaca_sign_ctx_s *nc = NULL;
const EVP_MD *md = NULL;
const struct yaca_key_evp_s *evp_key = key_get_evp(key);
if (ctx == NULL || evp_key == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (key->type) {
case YACA_KEY_TYPE_RSA_PRIV:
// case YACA_KEY_TYPE_EC_PRIV:
// TODO NOT_IMPLEMENTED
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
goto exit;
}
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-API int yaca_sign_hmac_init(yaca_ctx_h *ctx,
- yaca_digest_algo_e algo,
- const yaca_key_h key)
+API int yaca_sign_initialize_hmac(yaca_context_h *ctx,
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h key)
{
struct yaca_sign_ctx_s *nc = NULL;
EVP_PKEY *pkey = NULL;
if (ctx == NULL || simple_key == NULL ||
(key->type != YACA_KEY_TYPE_SYMMETRIC && key->type != YACA_KEY_TYPE_DES))
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
if (ret != YACA_ERROR_NONE)
pkey = NULL;
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
EVP_PKEY_free(pkey);
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-API int yaca_sign_cmac_init(yaca_ctx_h *ctx,
- yaca_enc_algo_e algo,
- const yaca_key_h key)
+API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
+ yaca_encrypt_algorithm_e algo,
+ const yaca_key_h key)
{
struct yaca_sign_ctx_s *nc = NULL;
CMAC_CTX* cmac_ctx = NULL;
if (ctx == NULL || simple_key == NULL ||
(key->type != YACA_KEY_TYPE_SYMMETRIC && key->type != YACA_KEY_TYPE_DES))
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
if (ret != YACA_ERROR_NONE)
pkey = NULL;
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
EVP_PKEY_free(pkey);
CMAC_CTX_free(cmac_ctx);
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-API int yaca_sign_update(yaca_ctx_h ctx,
+API int yaca_sign_update(yaca_context_h ctx,
const char *data,
size_t data_len)
{
if (c == NULL || c->op_type != OP_SIGN ||
data == NULL || data_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestSignUpdate(c->mdctx, data, data_len);
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_sign_final(yaca_ctx_h ctx,
- char *signature,
- size_t *signature_len)
+API int yaca_sign_finalize(yaca_context_h ctx,
+ char *signature,
+ size_t *signature_len)
{
struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
int ret;
if (c == NULL || c->op_type != OP_SIGN ||
signature == NULL || signature_len == NULL || *signature_len == 0)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestSignFinal(c->mdctx, (unsigned char *)signature, signature_len);
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_verify_init(yaca_ctx_h *ctx,
- yaca_digest_algo_e algo,
- const yaca_key_h key)
+API int yaca_verify_initialize(yaca_context_h *ctx,
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h key)
{
struct yaca_sign_ctx_s *nc = NULL;
const EVP_MD *md = NULL;
const struct yaca_key_evp_s *evp_key = key_get_evp(key);
if (ctx == NULL || evp_key == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
switch (key->type) {
case YACA_KEY_TYPE_RSA_PUB:
// case YACA_KEY_TYPE_EC_PUB:
// TODO NOT_IMPLEMENTED
default:
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
}
ret = yaca_zalloc(sizeof(struct yaca_sign_ctx_s), (void**)&nc);
goto exit;
}
- *ctx = (yaca_ctx_h)nc;
+ *ctx = (yaca_context_h)nc;
nc = NULL;
ret = YACA_ERROR_NONE;
exit:
- yaca_ctx_free((yaca_ctx_h)nc);
+ yaca_context_destroy((yaca_context_h)nc);
return ret;
}
-API int yaca_verify_update(yaca_ctx_h ctx,
+API int yaca_verify_update(yaca_context_h ctx,
const char *data,
size_t data_len)
{
int ret;
if (c == NULL || data == NULL || data_len == 0 || c->op_type != OP_VERIFY)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestVerifyUpdate(c->mdctx, data, data_len);
if (ret != 1) {
return YACA_ERROR_NONE;
}
-API int yaca_verify_final(yaca_ctx_h ctx,
- const char *signature,
- size_t signature_len)
+API int yaca_verify_finalize(yaca_context_h ctx,
+ const char *signature,
+ size_t signature_len)
{
struct yaca_sign_ctx_s *c = get_sign_ctx(ctx);
int ret;
if (c == NULL || signature == NULL || signature_len == 0 || c->op_type != OP_VERIFY)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestVerifyFinal(c->mdctx,
(unsigned char *)signature,
#include "internal.h"
-API int yaca_digest_calc(yaca_digest_algo_e algo,
- const char *data,
- size_t data_len,
- char **digest,
- size_t *digest_len)
+API int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
+ const char *data,
+ size_t data_len,
+ char **digest,
+ size_t *digest_len)
{
- yaca_ctx_h ctx;
+ yaca_context_h ctx;
int ret;
char *ldigest = NULL;
size_t ldigest_len;
if (data == NULL || data_len == 0 || digest == NULL || digest_len == NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
- ret = yaca_digest_init(&ctx, algo);
+ ret = yaca_digest_initialize(&ctx, algo);
if (ret != YACA_ERROR_NONE)
return ret;
if (ret != YACA_ERROR_NONE)
goto exit;
- ret = yaca_digest_final(ctx, ldigest, &ldigest_len);
+ ret = yaca_digest_finalize(ctx, ldigest, &ldigest_len);
if (ret != YACA_ERROR_NONE)
goto exit;
exit:
yaca_free(ldigest);
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}
-API int yaca_encrypt(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *plain,
- size_t plain_len,
- char **cipher,
- size_t *cipher_len)
+API int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *plain,
+ size_t plain_len,
+ char **cipher,
+ size_t *cipher_len)
{
- yaca_ctx_h ctx;
+ yaca_context_h ctx;
int ret;
char *lcipher = NULL;
size_t out_len, lcipher_len, written;
if (plain == NULL || plain_len == 0 || cipher == NULL || cipher_len == NULL ||
sym_key == YACA_KEY_NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
- ret = yaca_encrypt_init(&ctx, algo, bcm, sym_key, iv);
+ ret = yaca_encrypt_initialize(&ctx, algo, bcm, sym_key, iv);
if (ret != YACA_ERROR_NONE)
return ret;
goto exit;
if (out_len > SIZE_MAX - lcipher_len) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
written = out_len;
out_len = lcipher_len - written;
- ret = yaca_encrypt_final(ctx, lcipher + written, &out_len);
+ ret = yaca_encrypt_finalize(ctx, lcipher + written, &out_len);
if (ret != YACA_ERROR_NONE)
goto exit;
exit:
yaca_free(lcipher);
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}
-API int yaca_decrypt(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *cipher,
- size_t cipher_len,
- char **plain,
- size_t *plain_len)
+API int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *cipher,
+ size_t cipher_len,
+ char **plain,
+ size_t *plain_len)
{
- yaca_ctx_h ctx;
+ yaca_context_h ctx;
int ret;
char *lplain = NULL;
size_t out_len, lplain_len, written;
if (cipher == NULL || cipher_len == 0 || plain == NULL || plain_len == NULL ||
sym_key == YACA_KEY_NULL)
- return YACA_ERROR_INVALID_ARGUMENT;
+ return YACA_ERROR_INVALID_PARAMETER;
- ret = yaca_decrypt_init(&ctx, algo, bcm, sym_key, iv);
+ ret = yaca_decrypt_initialize(&ctx, algo, bcm, sym_key, iv);
if (ret != YACA_ERROR_NONE)
return ret;
goto exit;
if (out_len > SIZE_MAX - lplain_len) {
- ret = YACA_ERROR_INVALID_ARGUMENT;
+ ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
written = out_len;
out_len = lplain_len - written;
- ret = yaca_decrypt_final(ctx, lplain + written, &out_len);
+ ret = yaca_decrypt_finalize(ctx, lplain + written, &out_len);
if (ret != YACA_ERROR_NONE)
goto exit;
exit:
yaca_free(lplain);
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}
-static int sign(const yaca_ctx_h ctx, const char *data, size_t data_len,
+static int sign(const yaca_context_h ctx, const char *data, size_t data_len,
char **signature, size_t *signature_len)
{
int ret;
if (ret != YACA_ERROR_NONE)
return ret;
- ret = yaca_sign_final(ctx, *signature, signature_len);
+ ret = yaca_sign_finalize(ctx, *signature, signature_len);
if (ret != YACA_ERROR_NONE) {
yaca_free(*signature);
*signature = NULL;
return ret;
}
-API int yaca_sign(yaca_digest_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- char **signature,
- size_t *signature_len)
+API int yaca_simple_calculate_signature(yaca_digest_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ char **signature,
+ size_t *signature_len)
{
int ret;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
- ret = yaca_sign_init(&ctx, algo, key);
+ ret = yaca_sign_initialize(&ctx, algo, key);
if (ret != YACA_ERROR_NONE)
return ret;
ret = sign(ctx, data, data_len, signature, signature_len);
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}
-API int yaca_verify(yaca_digest_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- const char *signature,
- size_t signature_len)
+API int yaca_simple_verify_signature(yaca_digest_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ const char *signature,
+ size_t signature_len)
{
int ret;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
- ret = yaca_verify_init(&ctx, algo, key);
+ ret = yaca_verify_initialize(&ctx, algo, key);
if (ret != YACA_ERROR_NONE)
return ret;
if (ret != YACA_ERROR_NONE)
goto exit;
- ret = yaca_verify_final(ctx, signature, signature_len);
+ ret = yaca_verify_finalize(ctx, signature, signature_len);
exit:
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}
-API int yaca_hmac(yaca_digest_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- char **mac,
- size_t *mac_len)
+API int yaca_simple_calculate_hmac(yaca_digest_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ char **mac,
+ size_t *mac_len)
{
int ret;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
- ret = yaca_sign_hmac_init(&ctx, algo, key);
+ ret = yaca_sign_initialize_hmac(&ctx, algo, key);
if (ret != YACA_ERROR_NONE)
return ret;
ret = sign(ctx, data, data_len, mac, mac_len);
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}
-API int yaca_cmac(yaca_enc_algo_e algo,
- const yaca_key_h key,
- const char *data,
- size_t data_len,
- char **mac,
- size_t *mac_len)
+API int yaca_simple_calculate_cmac(yaca_encrypt_algorithm_e algo,
+ const yaca_key_h key,
+ const char *data,
+ size_t data_len,
+ char **mac,
+ size_t *mac_len)
{
int ret;
- yaca_ctx_h ctx = YACA_CTX_NULL;
+ yaca_context_h ctx = YACA_CONTEXT_NULL;
- ret = yaca_sign_cmac_init(&ctx, algo, key);
+ ret = yaca_sign_initialize_cmac(&ctx, algo, key);
if (ret != YACA_ERROR_NONE)
return ret;
ret = sign(ctx, data, data_len, mac, mac_len);
- yaca_ctx_free(ctx);
+ yaca_context_destroy(ctx);
return ret;
}