From 6a81623a26e1d8c08b355570dab8ad64ed89326a Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Wed, 25 May 2016 14:04:35 +0200 Subject: [PATCH 01/16] Add support for multiple threads Change-Id: I76451bc5ea76fd2277eb62f79aa435f4b4fbe64d --- src/CMakeLists.txt | 6 ++++- src/crypto.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e21ca95..a2e511e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -47,9 +47,13 @@ SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES ## Link libraries ############################################################## PKG_CHECK_MODULES(YACA_DEPS REQUIRED openssl capi-base-common) +FIND_PACKAGE (Threads) + INCLUDE_DIRECTORIES(${API_FOLDER}) INCLUDE_DIRECTORIES(SYSTEM ${YACA_DEPS_INCLUDE_DIRS}) -TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${YACA_DEPS_LIBRARIES}) +TARGET_LINK_LIBRARIES(${PROJECT_NAME} + ${YACA_DEPS_LIBRARIES} + ${CMAKE_THREAD_LIBS_INIT}) ## Generate the pc file ######################################################## CONFIGURE_FILE(${PC_FILE}.in ${CMAKE_CURRENT_BINARY_DIR}/${PC_FILE} @ONLY) diff --git a/src/crypto.c b/src/crypto.c index ec1d35b..d52468d 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -23,6 +23,7 @@ #include #include +#include #include #include @@ -34,19 +35,83 @@ #include "internal.h" +static pthread_mutex_t *mutexes = NULL; + +static void locking_callback(int mode, int type, const char* file, int line) +{ + /* Ignore NULL mutexes and lock/unlock error codes as we can't do anything + * about them. */ + + if (mutexes == NULL) + return; + + if (mode & CRYPTO_LOCK) + pthread_mutex_lock(&mutexes[type]); + else if (mode & CRYPTO_UNLOCK) + pthread_mutex_unlock(&mutexes[type]); +} + +static unsigned long thread_id_callback() +{ + return pthread_self(); +} + +static void destroy_mutexes(int count) +{ + if (mutexes != NULL) { + for (int i = 0; i < count; i++) { + /* Ignore returned value as we can't do anything about it */ + pthread_mutex_destroy(&mutexes[i]); + } + yaca_free(mutexes); + mutexes = NULL; + } +} + API int yaca_init(void) { + if (mutexes != NULL) + return YACA_ERROR_INTERNAL; // TODO introduce new one? OPENSSL_init(); OpenSSL_add_all_digests(); OpenSSL_add_all_ciphers(); + + /* enable threads support */ + mutexes = yaca_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t)); + if (mutexes == NULL) + return YACA_ERROR_OUT_OF_MEMORY; + + for (int i = 0; i < CRYPTO_num_locks(); i++) { + if (pthread_mutex_init(&mutexes[i], NULL) != 0) { + int ret = 0; + switch (errno) { + case ENOMEM: + ret = YACA_ERROR_OUT_OF_MEMORY; + break; + case EAGAIN: + case EPERM: + case EBUSY: + case EINVAL: + default: + ret = YACA_ERROR_INTERNAL; + } + destroy_mutexes(i); + + return ret; + } + } + + CRYPTO_set_id_callback(thread_id_callback); + CRYPTO_set_locking_callback(locking_callback); + /* TODO: - We should prepare for multithreading. Either we or the user should setup static locks. We should also decide on Openssl config. Here's a good tutorial for initalization and cleanup: https://wiki.openssl.org/index.php/Library_Initialization We should also initialize the entropy for random number generator: https://wiki.openssl.org/index.php/Random_Numbers#Initialization */ + return 0; } @@ -56,6 +121,12 @@ API void yaca_exit(void) ERR_remove_thread_state(NULL); EVP_cleanup(); CRYPTO_cleanup_all_ex_data(); + + /* threads support cleanup */ + CRYPTO_set_id_callback(NULL); + CRYPTO_set_locking_callback(NULL); + + destroy_mutexes(CRYPTO_num_locks()); } API void *yaca_malloc(size_t size) -- 2.7.4 From 1793563e6ecc522c6ff2d486faeba07cd13388d6 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 27 May 2016 12:43:54 +0200 Subject: [PATCH 02/16] Modify header names according to ACR Change-Id: I0bf4ad69d5f2c5796d26e2970ab4ef9d9583b91c --- CMakeLists.txt | 2 +- api/yaca/{crypto.h => yaca_crypto.h} | 2 +- api/yaca/{digest.h => yaca_digest.h} | 2 +- api/yaca/{encrypt.h => yaca_encrypt.h} | 2 +- api/yaca/{error.h => yaca_error.h} | 0 api/yaca/{key.h => yaca_key.h} | 2 +- api/yaca/{seal.h => yaca_seal.h} | 2 +- api/yaca/{sign.h => yaca_sign.h} | 2 +- api/yaca/{simple.h => yaca_simple.h} | 2 +- api/yaca/{types.h => yaca_types.h} | 0 examples/CMakeLists.txt | 2 +- examples/digest.c | 8 ++++---- examples/encrypt.c | 10 +++++----- examples/encrypt_aes_gcm_ccm.c | 8 ++++---- examples/key_exchange.c | 6 +++--- examples/key_import_export.c | 6 +++--- examples/key_password.c | 8 ++++---- examples/misc.c | 2 +- examples/seal.c | 8 ++++---- examples/sign.c | 10 +++++----- src/CMakeLists.txt | 2 +- src/crypto.c | 4 ++-- src/digest.c | 6 +++--- src/encrypt.c | 8 ++++---- src/internal.h | 2 +- src/key.c | 6 +++--- src/seal.c | 8 ++++---- src/sign.c | 8 ++++---- src/simple.c | 12 ++++++------ src/yaca.pc.in | 2 +- 30 files changed, 71 insertions(+), 71 deletions(-) rename api/yaca/{crypto.h => yaca_crypto.h} (99%) rename api/yaca/{digest.h => yaca_digest.h} (99%) rename api/yaca/{encrypt.h => yaca_encrypt.h} (99%) rename api/yaca/{error.h => yaca_error.h} (100%) rename api/yaca/{key.h => yaca_key.h} (99%) rename api/yaca/{seal.h => yaca_seal.h} (99%) rename api/yaca/{sign.h => yaca_sign.h} (99%) rename api/yaca/{simple.h => yaca_simple.h} (99%) rename api/yaca/{types.h => yaca_types.h} (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index aa4f6ac..e2b5e35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ IF("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang") ENDIF() ## Subdirectories ############################################################## -SET(API_FOLDER ${PROJECT_SOURCE_DIR}/api) +SET(API_FOLDER ${PROJECT_SOURCE_DIR}/api/yaca) SET(EXAMPLES_FOLDER ${PROJECT_SOURCE_DIR}/examples) SET(SRC_FOLDER ${PROJECT_SOURCE_DIR}/src) diff --git a/api/yaca/crypto.h b/api/yaca/yaca_crypto.h similarity index 99% rename from api/yaca/crypto.h rename to api/yaca/yaca_crypto.h index 5a44a9d..1fabf47 100644 --- a/api/yaca/crypto.h +++ b/api/yaca/yaca_crypto.h @@ -25,7 +25,7 @@ #define YACA_CRYPTO_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/digest.h b/api/yaca/yaca_digest.h similarity index 99% rename from api/yaca/digest.h rename to api/yaca/yaca_digest.h index 1938360..cb27246 100644 --- a/api/yaca/digest.h +++ b/api/yaca/yaca_digest.h @@ -25,7 +25,7 @@ #define YACA_DIGEST_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/encrypt.h b/api/yaca/yaca_encrypt.h similarity index 99% rename from api/yaca/encrypt.h rename to api/yaca/yaca_encrypt.h index de7bc58..94bedff 100644 --- a/api/yaca/encrypt.h +++ b/api/yaca/yaca_encrypt.h @@ -25,7 +25,7 @@ #define YACA_ENCRYPT_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/error.h b/api/yaca/yaca_error.h similarity index 100% rename from api/yaca/error.h rename to api/yaca/yaca_error.h diff --git a/api/yaca/key.h b/api/yaca/yaca_key.h similarity index 99% rename from api/yaca/key.h rename to api/yaca/yaca_key.h index e03834d..4c4642c 100755 --- a/api/yaca/key.h +++ b/api/yaca/yaca_key.h @@ -25,7 +25,7 @@ #define YACA_KEY_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/seal.h b/api/yaca/yaca_seal.h similarity index 99% rename from api/yaca/seal.h rename to api/yaca/yaca_seal.h index 2940f01..0b7f808 100644 --- a/api/yaca/seal.h +++ b/api/yaca/yaca_seal.h @@ -25,7 +25,7 @@ #define YACA_SEAL_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/sign.h b/api/yaca/yaca_sign.h similarity index 99% rename from api/yaca/sign.h rename to api/yaca/yaca_sign.h index 36ba4dc..9deebec 100644 --- a/api/yaca/sign.h +++ b/api/yaca/yaca_sign.h @@ -25,7 +25,7 @@ #define YACA_SIGN_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/simple.h b/api/yaca/yaca_simple.h similarity index 99% rename from api/yaca/simple.h rename to api/yaca/yaca_simple.h index 9c62314..f743de2 100644 --- a/api/yaca/simple.h +++ b/api/yaca/yaca_simple.h @@ -25,7 +25,7 @@ #define YACA_SIMPLE_H #include -#include +#include #ifdef __cplusplus extern "C" { diff --git a/api/yaca/types.h b/api/yaca/yaca_types.h similarity index 100% rename from api/yaca/types.h rename to api/yaca/yaca_types.h diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 0d6f3e1..af00c1c 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -20,7 +20,7 @@ # @author Krzysztof Jackiewicz (k.jackiewicz@samsung.com) # -INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}/api) +INCLUDE_DIRECTORIES(${API_FOLDER}) SET(COMMON_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/lorem.c ${CMAKE_CURRENT_SOURCE_DIR}/misc.c) diff --git a/examples/digest.c b/examples/digest.c index 9e01fc1..685bd8a 100644 --- a/examples/digest.c +++ b/examples/digest.c @@ -21,10 +21,10 @@ * @brief */ -#include -#include -#include -#include +#include +#include +#include +#include #include "lorem.h" #include "misc.h" diff --git a/examples/encrypt.c b/examples/encrypt.c index ec2ee2f..0ee5e42 100644 --- a/examples/encrypt.c +++ b/examples/encrypt.c @@ -23,11 +23,11 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "lorem.h" #include "misc.h" diff --git a/examples/encrypt_aes_gcm_ccm.c b/examples/encrypt_aes_gcm_ccm.c index 4ae8ff6..7fe5305 100644 --- a/examples/encrypt_aes_gcm_ccm.c +++ b/examples/encrypt_aes_gcm_ccm.c @@ -23,10 +23,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "lorem.h" #include "misc.h" diff --git a/examples/key_exchange.c b/examples/key_exchange.c index 559059e..80bce46 100644 --- a/examples/key_exchange.c +++ b/examples/key_exchange.c @@ -23,9 +23,9 @@ #include -#include -#include -#include +#include +#include +#include #include "misc.h" #include "../src/debug.h" diff --git a/examples/key_import_export.c b/examples/key_import_export.c index 9c44266..6b647fd 100644 --- a/examples/key_import_export.c +++ b/examples/key_import_export.c @@ -23,9 +23,9 @@ #include -#include -#include -#include +#include +#include +#include #include "misc.h" #include "../src/debug.h" diff --git a/examples/key_password.c b/examples/key_password.c index e3e20c2..d76f195 100644 --- a/examples/key_password.c +++ b/examples/key_password.c @@ -18,10 +18,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "misc.h" #include "../src/debug.h" diff --git a/examples/misc.c b/examples/misc.c index 1846d5e..7eaedf3 100644 --- a/examples/misc.c +++ b/examples/misc.c @@ -29,7 +29,7 @@ #include -#include +#include #include "misc.h" diff --git a/examples/seal.c b/examples/seal.c index 0811f43..a2359a7 100644 --- a/examples/seal.c +++ b/examples/seal.c @@ -23,10 +23,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "lorem.h" #include "misc.h" diff --git a/examples/sign.c b/examples/sign.c index a6f4ee8..48f6dca 100644 --- a/examples/sign.c +++ b/examples/sign.c @@ -23,11 +23,11 @@ #include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include #include "lorem.h" #include "misc.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a2e511e..ae4168b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -25,7 +25,7 @@ PROJECT(yaca) MESSAGE(STATUS "") MESSAGE(STATUS "Generating makefile for the yaca...") -FILE(GLOB HEADERS ${API_FOLDER}/yaca/*.h) +FILE(GLOB HEADERS ${API_FOLDER}/*.h) FILE(GLOB SRCS *.c *.h) SET(_LIB_VERSION_ "${VERSION}") diff --git a/src/crypto.c b/src/crypto.c index d52468d..c0ce1f4 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -30,8 +30,8 @@ #include #include -#include -#include +#include +#include #include "internal.h" diff --git a/src/digest.c b/src/digest.c index 28b095e..a7e9bbe 100644 --- a/src/digest.c +++ b/src/digest.c @@ -25,9 +25,9 @@ #include -#include -#include -#include +#include +#include +#include #include "internal.h" diff --git a/src/encrypt.c b/src/encrypt.c index c3d93ee..c059c7e 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -26,10 +26,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "internal.h" diff --git a/src/internal.h b/src/internal.h index 16b8b38..660bbd2 100644 --- a/src/internal.h +++ b/src/internal.h @@ -29,7 +29,7 @@ #include #include -#include +#include #define API __attribute__ ((visibility ("default"))) diff --git a/src/key.c b/src/key.c index 8077f31..dd4e648 100755 --- a/src/key.c +++ b/src/key.c @@ -34,9 +34,9 @@ #include #include -#include -#include -#include +#include +#include +#include #include "internal.h" diff --git a/src/seal.c b/src/seal.c index a3d3eb1..1dc583e 100644 --- a/src/seal.c +++ b/src/seal.c @@ -26,10 +26,10 @@ #include -#include -#include -#include -#include +#include +#include +#include +#include #include "internal.h" diff --git a/src/sign.c b/src/sign.c index 4f749e8..bc9b137 100644 --- a/src/sign.c +++ b/src/sign.c @@ -28,10 +28,10 @@ #include #include -#include -#include -#include -#include +#include +#include +#include +#include #include "internal.h" diff --git a/src/simple.c b/src/simple.c index 2597c02..04db0fa 100644 --- a/src/simple.c +++ b/src/simple.c @@ -24,12 +24,12 @@ #include #include -#include -#include -#include -#include -#include -#include +#include +#include +#include +#include +#include +#include #include "internal.h" diff --git a/src/yaca.pc.in b/src/yaca.pc.in index c33c857..fe501b1 100644 --- a/src/yaca.pc.in +++ b/src/yaca.pc.in @@ -9,4 +9,4 @@ Name: yaca Description: Yet Another Crypto API Version: @_LIB_VERSION_@ Libs: -L${libdir} -l@PROJECT_NAME@ -Cflags: -I${includedir} +Cflags: -I${includedir}/yaca -- 2.7.4 From 06f7e3af90bff25122abf388f4731946a56b70a1 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 27 May 2016 13:33:07 +0200 Subject: [PATCH 03/16] Introduce YACA_ERROR_NONE according to ACR. Change-Id: Id1f479603c7c54b9e5d5f187dd632470553aac10 --- api/yaca/yaca_crypto.h | 10 +++--- api/yaca/yaca_digest.h | 6 ++-- api/yaca/yaca_encrypt.h | 14 ++++---- api/yaca/yaca_key.h | 18 +++++----- api/yaca/yaca_seal.h | 12 +++---- api/yaca/yaca_sign.h | 16 ++++----- api/yaca/yaca_simple.h | 14 ++++---- examples/digest.c | 16 ++++----- examples/encrypt.c | 38 ++++++++++----------- examples/encrypt_aes_gcm_ccm.c | 76 +++++++++++++++++++++--------------------- examples/key_exchange.c | 18 +++++----- examples/key_import_export.c | 68 ++++++++++++++++++------------------- examples/key_password.c | 16 ++++----- examples/seal.c | 26 +++++++-------- examples/sign.c | 76 +++++++++++++++++++++--------------------- src/crypto.c | 8 ++--- src/digest.c | 14 ++++---- src/encrypt.c | 24 ++++++------- src/key.c | 60 ++++++++++++++++----------------- src/seal.c | 16 ++++----- src/sign.c | 32 +++++++++--------- src/simple.c | 50 +++++++++++++-------------- 22 files changed, 314 insertions(+), 314 deletions(-) diff --git a/api/yaca/yaca_crypto.h b/api/yaca/yaca_crypto.h index 1fabf47..30c2734 100644 --- a/api/yaca/yaca_crypto.h +++ b/api/yaca/yaca_crypto.h @@ -51,7 +51,7 @@ extern "C" { * * @since_tizen 3.0 * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_exit() */ int yaca_init(void); @@ -122,7 +122,7 @@ void yaca_free(void *ptr); * @param[in,out] data Pointer to the memory to be randomized. * @param[in] data_len Length of the memory to be randomized. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_rand_bytes(char *data, size_t data_len); @@ -137,7 +137,7 @@ int yaca_rand_bytes(char *data, size_t data_len); * @param[in] value Parameter value. * @param[in] value_len Length of the parameter value. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_ex_param_e, yaca_ctx_get_param() */ int yaca_ctx_set_param(yaca_ctx_h ctx, @@ -156,7 +156,7 @@ int yaca_ctx_set_param(yaca_ctx_h ctx, * @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. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_ex_param_e, yaca_ctx_set_param() */ int yaca_ctx_get_param(const yaca_ctx_h ctx, @@ -220,7 +220,7 @@ int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *outpu * @param[in] second Pointer to the second buffer. * @param[in] len Length to compare. * - * @return 0 when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH + * @return YACA_ERROR_NONE when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH */ int yaca_memcmp(const void *first, const void *second, size_t len); diff --git a/api/yaca/yaca_digest.h b/api/yaca/yaca_digest.h index cb27246..2c7be86 100644 --- a/api/yaca/yaca_digest.h +++ b/api/yaca/yaca_digest.h @@ -47,7 +47,7 @@ extern "C" { * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()). * @param[in] algo Digest algorithm that will be used. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_digest_algo_e, yaca_digest_update(), yaca_digest_final() */ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); @@ -61,7 +61,7 @@ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); * @param[in] data Data from which the digest is to be calculated. * @param[in] data_len Length of the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_digest_init(), yaca_digest_final() */ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); @@ -76,7 +76,7 @@ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); * see yaca_get_digest_length()). * @param[out] digest_len Length of the digest, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_digest_init(), yaca_digest_update() */ int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len); diff --git a/api/yaca/yaca_encrypt.h b/api/yaca/yaca_encrypt.h index 94bedff..cba5332 100644 --- a/api/yaca/yaca_encrypt.h +++ b/api/yaca/yaca_encrypt.h @@ -50,7 +50,7 @@ extern "C" { * @param[in] sym_key Symmetric key that will be used. * @param[in] iv Initialization vector that will be used. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_encrypt_update(), yaca_encrypt_final() */ int yaca_encrypt_init(yaca_ctx_h *ctx, @@ -71,7 +71,7 @@ int yaca_encrypt_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_encrypt_init(), yaca_encrypt_final() */ int yaca_encrypt_update(yaca_ctx_h ctx, @@ -90,7 +90,7 @@ int yaca_encrypt_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_encrypt_init(), yaca_encrypt_update() */ int yaca_encrypt_final(yaca_ctx_h ctx, @@ -108,7 +108,7 @@ int yaca_encrypt_final(yaca_ctx_h ctx, * @param[in] sym_key Symmetric key that was used to encrypt the data. * @param[in] iv Initialization vector that was used to encrypt the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_decrypt_update(), yaca_decrypt_final() */ int yaca_decrypt_init(yaca_ctx_h *ctx, @@ -129,7 +129,7 @@ int yaca_decrypt_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_decrypt_init(), yaca_decrypt_final() */ int yaca_decrypt_update(yaca_ctx_h ctx, @@ -148,7 +148,7 @@ int yaca_decrypt_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_decrypt_init(), yaca_decrypt_update() */ int yaca_decrypt_final(yaca_ctx_h ctx, @@ -168,7 +168,7 @@ int yaca_decrypt_final(yaca_ctx_h ctx, * @param[in] key_bits Key length in bits. * @param[out] iv_bits Recommended IV length in bits. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_get_iv_bits(yaca_enc_algo_e algo, yaca_block_cipher_mode_e bcm, diff --git a/api/yaca/yaca_key.h b/api/yaca/yaca_key.h index 4c4642c..4786d9a 100755 --- a/api/yaca/yaca_key.h +++ b/api/yaca/yaca_key.h @@ -51,7 +51,7 @@ extern "C" { * @param[in] key Key which type we return. * @param[out] key_type Key type. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type); @@ -63,7 +63,7 @@ int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type); * @param[in] key Key which length we return. * @param[out] key_bits Key length in bits. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits); @@ -94,7 +94,7 @@ int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits); * @param[in] data Blob containing the key. * @param[in] data_len Size of the blob. * - * @return 0 on success, YACA_ERROR_PASSWORD_INVALID if wrong password given, + * @return YACA_ERROR_NONE on success, YACA_ERROR_PASSWORD_INVALID if wrong password given, * negative on error. * @see #yaca_key_type_e, yaca_key_export(), yaca_key_free() */ @@ -136,7 +136,7 @@ int yaca_key_import(yaca_key_h *key, * (must be freed with yaca_free()). * @param[out] data_len Size of the output data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_fmt_e, #yaca_key_file_fmt_e, yaca_key_import(), yaca_key_free() */ int yaca_key_export(const yaca_key_h key, @@ -157,7 +157,7 @@ int yaca_key_export(const yaca_key_h key, * @param[in] key_type Type of the key to be generated. * @param[in] key_bits Length of the key (in bits) to be generated. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_key_bits_e, yaca_key_free() */ int yaca_key_gen(yaca_key_h *key, @@ -172,7 +172,7 @@ int yaca_key_gen(yaca_key_h *key, * @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()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_key_gen(), yaca_key_import(), yaca_key_free() */ int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key); @@ -206,7 +206,7 @@ void yaca_key_free(yaca_key_h key); * @param[out] sym_key Shared secret, that can be used as a symmetric key * (must be freed with yaca_key_free()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_derive_dh(const yaca_key_h prv_key, const yaca_key_h pub_key, @@ -224,7 +224,7 @@ int yaca_key_derive_dh(const yaca_key_h prv_key, * @param[out] sym_key Shared secret, that can be used as a symmetric key * (must be freed with yaca_key_free()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_derive_kea(const yaca_key_h prv_key, const yaca_key_h pub_key, @@ -245,7 +245,7 @@ int yaca_key_derive_kea(const yaca_key_h prv_key, * @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()). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_key_derive_pbkdf2(const char *password, const char *salt, diff --git a/api/yaca/yaca_seal.h b/api/yaca/yaca_seal.h index 0b7f808..81cd401 100644 --- a/api/yaca/yaca_seal.h +++ b/api/yaca/yaca_seal.h @@ -56,7 +56,7 @@ extern "C" { * @param[out] sym_key Generated symmetric key that will be used. It is encrypted with peer's public key. * @param[out] iv Generated initialization vector that will be used. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_seal_update(), yaca_seal_final() */ int yaca_seal_init(yaca_ctx_h *ctx, @@ -79,7 +79,7 @@ int yaca_seal_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_seal_init(), yaca_seal_final() */ int yaca_seal_update(yaca_ctx_h ctx, @@ -98,7 +98,7 @@ int yaca_seal_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_seal_init(), yaca_seal_update() */ int yaca_seal_final(yaca_ctx_h ctx, @@ -118,7 +118,7 @@ int yaca_seal_final(yaca_ctx_h ctx, * @param[in] sym_key Symmetric key, encrypted with the public key, that was used to encrypt the data. * @param[in] iv Initialization vector that was used for the encryption. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_open_update(), yaca_open_final() */ int yaca_open_init(yaca_ctx_h *ctx, @@ -141,7 +141,7 @@ int yaca_open_init(yaca_ctx_h *ctx, * yaca_get_output_length()). * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_open_init(), yaca_open_final() */ int yaca_open_update(yaca_ctx_h ctx, @@ -160,7 +160,7 @@ int yaca_open_update(yaca_ctx_h ctx, * yaca_get_block_length()). * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_open_init(), yaca_open_update() */ int yaca_open_final(yaca_ctx_h ctx, diff --git a/api/yaca/yaca_sign.h b/api/yaca/yaca_sign.h index 9deebec..d8098c6 100644 --- a/api/yaca/yaca_sign.h +++ b/api/yaca/yaca_sign.h @@ -56,7 +56,7 @@ extern "C" { * - #YACA_KEY_TYPE_DSA_PRIV, * - #YACA_KEY_TYPE_EC_PRIV. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign_update(), * yaca_sign_final(), yaca_verify_init(), yaca_verify_update(), * yaca_verify_final() @@ -79,7 +79,7 @@ int yaca_sign_init(yaca_ctx_h *ctx, * - #YACA_KEY_TYPE_SYMMETRIC, * - #YACA_KEY_TYPE_DES. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign_update(), * yaca_sign_final(), yaca_memcmp() */ @@ -101,7 +101,7 @@ int yaca_sign_hmac_init(yaca_ctx_h *ctx, * - #YACA_KEY_TYPE_SYMMETRIC, * - #YACA_KEY_TYPE_DES. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_enc_algo_e, yaca_sign_update(), * yaca_sign_final(), yaca_memcmp() */ @@ -119,7 +119,7 @@ int yaca_sign_cmac_init(yaca_ctx_h *ctx, * @param[in] data Data to be signed. * @param[in] data_len Length of the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_sign_init(), yaca_sign_final(), yaca_sign_hmac_init(), * yaca_sign_cmac_init() */ @@ -138,7 +138,7 @@ int yaca_sign_update(yaca_ctx_h ctx, * @param[out] signature_len Length of the MAC or the signature, * actual number of bytes written will be returned here. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_sign_init(), yaca_sign_update(), yaca_sign_hmac_init(), * yaca_sign_cmac_init() */ @@ -159,7 +159,7 @@ int yaca_sign_final(yaca_ctx_h ctx, * - #YACA_KEY_TYPE_DSA_PUB, * - #YACA_KEY_TYPE_EC_PUB. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_verify_update(), * yaca_verify_final() */ @@ -176,7 +176,7 @@ int yaca_verify_init(yaca_ctx_h *ctx, * @param[in] data Data to be verified. * @param[in] data_len Length of the data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see yaca_verify_init(), yaca_verify_final() */ int yaca_verify_update(yaca_ctx_h ctx, @@ -192,7 +192,7 @@ int yaca_verify_update(yaca_ctx_h ctx, * @param[in] signature Input signature (returned by yaca_sign_final()). * @param[in] signature_len Size of the signature. * - * @return 0 on success, YACA_ERROR_DATA_MISMATCH if verification fails, + * @return YACA_ERROR_NONE on success, YACA_ERROR_DATA_MISMATCH if verification fails, * negative on error. * @see yaca_verify_init(), yaca_verify_update() */ diff --git a/api/yaca/yaca_simple.h b/api/yaca/yaca_simple.h index f743de2..e50f7b2 100644 --- a/api/yaca/yaca_simple.h +++ b/api/yaca/yaca_simple.h @@ -59,7 +59,7 @@ extern "C" { * (should be freed with yaca_free()). * @param[out] digest_len Length of message digest (depends on algorithm). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_digest_algo_e */ int yaca_digest_calc(yaca_digest_algo_e algo, @@ -83,7 +83,7 @@ int yaca_digest_calc(yaca_digest_algo_e algo, * (should be freed with yaca_free()). * @param[out] cipher_len Length of the encrypted data (may be larger than decrypted). * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_decrypt() */ int yaca_encrypt(yaca_enc_algo_e algo, @@ -110,7 +110,7 @@ int yaca_encrypt(yaca_enc_algo_e algo, * (should be freed with yaca_free()). * @param[out] plain_len Length of the decrypted data. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_encrypt() */ int yaca_decrypt(yaca_enc_algo_e algo, @@ -139,7 +139,7 @@ int yaca_decrypt(yaca_enc_algo_e algo, * library. Should be freed with yaca_free(). * @param[out] signature_len Length of the signature. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_verify(), */ int yaca_sign(yaca_digest_algo_e algo, @@ -165,7 +165,7 @@ int yaca_sign(yaca_digest_algo_e algo, * @param[in] signature Message signature. * @param[in] signature_len Length of the signature. * - * @return 0 on success, YACA_ERROR_SIGNATURE_INVALID if verification fails, + * @return YACA_ERROR_NONE on success, YACA_ERROR_SIGNATURE_INVALID if verification fails, * negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign(), */ @@ -194,7 +194,7 @@ int yaca_verify(yaca_digest_algo_e algo, * with yaca_free(). * @param[out] mac_len Length of the MAC. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_memcmp() */ int yaca_hmac(yaca_digest_algo_e algo, @@ -222,7 +222,7 @@ int yaca_hmac(yaca_digest_algo_e algo, * with yaca_free(). * @param[out] mac_len Length of the MAC. * - * @return 0 on success, negative on error. + * @return YACA_ERROR_NONE on success, negative on error. * @see #yaca_key_type_e, #yaca_enc_algo_e, yaca_memcmp() */ int yaca_cmac(yaca_enc_algo_e algo, diff --git a/examples/digest.c b/examples/digest.c index 685bd8a..e4699e9 100644 --- a/examples/digest.c +++ b/examples/digest.c @@ -32,14 +32,14 @@ void digest_simple(void) { - int ret = 0; + int ret = YACA_ERROR_NONE; char *digest; size_t digest_len; ret = yaca_digest_calc(YACA_DIGEST_SHA256, lorem1024, 1024, &digest, &digest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return; dump_hex(digest, digest_len, "Message digest: "); @@ -49,27 +49,27 @@ void digest_simple(void) void digest_advanced(void) { - int ret = 0; + int ret = YACA_ERROR_NONE; yaca_ctx_h ctx; ret = yaca_digest_init(&ctx, YACA_DIGEST_SHA256); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return; ret = yaca_digest_update(ctx, lorem1024, 1024); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit_ctx; size_t digest_len; ret = yaca_get_digest_length(ctx, &digest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit_ctx; { char digest[digest_len]; ret = yaca_digest_final(ctx, digest, &digest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit_ctx; dump_hex(digest, digest_len, "Message digest: "); @@ -84,7 +84,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; digest_simple(); diff --git a/examples/encrypt.c b/examples/encrypt.c index 0ee5e42..ca84b1c 100644 --- a/examples/encrypt.c +++ b/examples/encrypt.c @@ -50,21 +50,21 @@ void encrypt_simple(const yaca_enc_algo_e algo, /* Key generation */ if (yaca_key_derive_pbkdf2("foo bar", "123456789", 10, 1000, - YACA_DIGEST_SHA256, key_bits, &key) != 0) + YACA_DIGEST_SHA256, key_bits, &key) != YACA_ERROR_NONE) return; - if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != 0) + if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE) goto exit; - if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto exit; - if (yaca_encrypt(algo, bcm, key, iv, lorem4096, LOREM4096_SIZE, &enc, &enc_size) != 0) + if (yaca_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) != 0) + if (yaca_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); @@ -100,24 +100,24 @@ void encrypt_advanced(const yaca_enc_algo_e algo, printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Key generation */ - if (yaca_key_gen(&key, key_type, key_bits) != 0) + if (yaca_key_gen(&key, key_type, key_bits) != YACA_ERROR_NONE) return; - if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != 0) + if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != YACA_ERROR_NONE) goto ex_key; - if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (iv_bits > 0 && yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto ex_key; /* Encryption */ { - if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto ex_iv; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_ctx; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_ctx; /* Calculate max output: size of update + final chunks */ @@ -126,11 +126,11 @@ void encrypt_advanced(const yaca_enc_algo_e algo, goto ex_ctx; out_size = enc_size; - if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto ex_of; rem = enc_size - out_size; - if (yaca_encrypt_final(ctx, enc + out_size, &rem) != 0) + if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto ex_of; enc_size = rem + out_size; @@ -143,13 +143,13 @@ void encrypt_advanced(const yaca_enc_algo_e algo, /* Decryption */ { - if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_of; /* Calculate max output: size of update + final chunks */ @@ -158,11 +158,11 @@ void encrypt_advanced(const yaca_enc_algo_e algo, goto ex_of; out_size = dec_size; - if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto ex_in; rem = dec_size - out_size; - if (yaca_decrypt_final(ctx, dec + out_size, &rem) != 0) + if (yaca_decrypt_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE) goto ex_in; dec_size = rem + out_size; @@ -187,7 +187,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; yaca_enc_algo_e algo = YACA_ENC_AES; diff --git a/examples/encrypt_aes_gcm_ccm.c b/examples/encrypt_aes_gcm_ccm.c index 7fe5305..00cffca 100644 --- a/examples/encrypt_aes_gcm_ccm.c +++ b/examples/encrypt_aes_gcm_ccm.c @@ -63,17 +63,17 @@ void encrypt_decrypt_aes_gcm(void) printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Key generation */ - if (yaca_key_gen(&key, key_type, key_bits) != 0) + if (yaca_key_gen(&key, key_type, key_bits) != YACA_ERROR_NONE) return; /* IV generation */ - if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto clean; if ((aad = yaca_zalloc(aad_size)) == NULL) goto clean; - if (yaca_rand_bytes(aad, aad_size) != 0) + if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE) goto clean; if ((tag = yaca_zalloc(tag_size)) == NULL) @@ -81,17 +81,17 @@ void encrypt_decrypt_aes_gcm(void) /* Encryption */ { - if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Provide any AAD data */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -100,21 +100,21 @@ void encrypt_decrypt_aes_gcm(void) goto clean; out_size = enc_size; - if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto clean; rem = enc_size - out_size; - if (yaca_encrypt_final(ctx, enc + out_size, &rem) != 0) + if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto clean; 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, - (void*)&tag_size, sizeof(tag_size)) != 0) + (void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE) goto clean; - if (yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void**)tag, &tag_size) != 0) + if (yaca_ctx_get_param(ctx, YACA_PARAM_GCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE) goto clean; dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size); @@ -125,17 +125,17 @@ void encrypt_decrypt_aes_gcm(void) /* Decryption */ { - if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Provide any AAD data */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -144,16 +144,16 @@ void encrypt_decrypt_aes_gcm(void) goto clean; out_size = dec_size; - if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto clean; 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) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_GCM_TAG, tag, tag_size) != YACA_ERROR_NONE) goto clean; - if (yaca_decrypt_final(ctx, dec + out_size, &rem) != 0) + if (yaca_decrypt_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE) goto clean; dec_size = rem + out_size; @@ -203,17 +203,17 @@ void encrypt_decrypt_aes_ccm(void) printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Key generation */ - if (yaca_key_gen(&key, key_type, key_bits) != 0) + if (yaca_key_gen(&key, key_type, key_bits) != YACA_ERROR_NONE) return; /* IV generation */ - if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != 0) + if (yaca_key_gen(&iv, YACA_KEY_TYPE_IV, iv_bits) != YACA_ERROR_NONE) goto clean; if ((aad = yaca_zalloc(aad_size)) == NULL) goto clean; - if (yaca_rand_bytes(aad, aad_size) != 0) + if (yaca_rand_bytes(aad, aad_size) != YACA_ERROR_NONE) goto clean; if ((tag = yaca_zalloc(tag_size)) == NULL) @@ -221,25 +221,25 @@ void encrypt_decrypt_aes_ccm(void) /* Encryption */ { - if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_encrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Set tag length (optionally) */ if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG_LEN, - (void*)&tag_size, sizeof(tag_size)) != 0) + (void*)&tag_size, sizeof(tag_size)) != YACA_ERROR_NONE) goto clean; /* The total plain text length must be passed (only needed if AAD is passed) */ - if (yaca_encrypt_update(ctx, NULL, LOREM4096_SIZE , NULL, &len) != 0) + if (yaca_encrypt_update(ctx, NULL, LOREM4096_SIZE , NULL, &len) != YACA_ERROR_NONE) goto clean; - if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -248,17 +248,17 @@ void encrypt_decrypt_aes_ccm(void) goto clean; out_size = enc_size; - if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_encrypt_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto clean; rem = enc_size - out_size; - if (yaca_encrypt_final(ctx, enc + out_size, &rem) != 0) + if (yaca_encrypt_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto clean; 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) != 0) + if (yaca_ctx_get_param(ctx, YACA_PARAM_CCM_TAG, (void**)tag, &tag_size) != YACA_ERROR_NONE) goto clean; dump_hex(enc, 16, "Encrypted data (16 of %zu bytes): ", enc_size); @@ -269,24 +269,24 @@ void encrypt_decrypt_aes_ccm(void) /* Decryption */ { - if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != 0) + if (yaca_decrypt_init(&ctx, algo, bcm, key, iv) != YACA_ERROR_NONE) goto clean; /* Set expected tag value */ - if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG, tag, tag_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_TAG, tag, tag_size) != YACA_ERROR_NONE) goto clean; /* The total encrypted text length must be passed (only needed if AAD is passed) */ - if (yaca_decrypt_update(ctx, NULL, enc_size , NULL, &len) != 0) + if (yaca_decrypt_update(ctx, NULL, enc_size , NULL, &len) != YACA_ERROR_NONE) goto clean; - if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_CCM_AAD, aad, aad_size) != YACA_ERROR_NONE) goto clean; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto clean; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto clean; /* Calculate max output: size of update + final chunks */ @@ -297,7 +297,7 @@ void encrypt_decrypt_aes_ccm(void) 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() */ - if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_decrypt_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto clean; dec_size = out_size; @@ -320,7 +320,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; encrypt_decrypt_aes_gcm(); diff --git a/examples/key_exchange.c b/examples/key_exchange.c index 80bce46..4bcfce6 100644 --- a/examples/key_exchange.c +++ b/examples/key_exchange.c @@ -45,11 +45,11 @@ void key_exchange_dh(void) // generate private, public key ret = yaca_key_gen(&private_key, YACA_KEY_TYPE_DH_PRIV, YACA_KEY_2048BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; ret = yaca_key_extract_public(private_key, &public_key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // get peer public key from file @@ -72,12 +72,12 @@ void key_exchange_dh(void) ret = yaca_key_import(&peer_key, YACA_KEY_TYPE_DH_PUB, NULL, buffer, size); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // derive secret ret = yaca_key_derive_dh(private_key, peer_key, &secret); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; clean: @@ -105,11 +105,11 @@ void key_exchange_ecdh(void) // generate private, public key ret = yaca_key_gen(&private_key, YACA_KEY_TYPE_EC_PRIV, YACA_KEY_CURVE_P256); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; ret = yaca_key_extract_public(private_key, &public_key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // get peer public key from file @@ -131,12 +131,12 @@ void key_exchange_ecdh(void) goto clean; ret = yaca_key_import(&peer_key, YACA_KEY_TYPE_EC_PUB, NULL, buffer, size); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; // derive secret ret = yaca_key_derive_dh(private_key, peer_key, &secret); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto clean; clean: @@ -154,7 +154,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; key_exchange_dh(); diff --git a/examples/key_import_export.c b/examples/key_import_export.c index 6b647fd..0a79fdf 100644 --- a/examples/key_import_export.c +++ b/examples/key_import_export.c @@ -46,10 +46,10 @@ int key_import_export_sym(yaca_key_h sym) /* BASE64 */ ret = yaca_key_export(sym, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_BASE64, NULL, &b64, &b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_key_import(&b64_imported, YACA_KEY_TYPE_SYMMETRIC, NULL, b64, b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** BASE64 exported key: *****\n%.*s\n", (int)b64_len, b64); @@ -57,7 +57,7 @@ int key_import_export_sym(yaca_key_h sym) b64 = NULL; ret = yaca_key_export(b64_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_BASE64, NULL, &b64, &b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***** BASE64 imported key: *****\n%.*s\n", (int)b64_len, b64); @@ -66,10 +66,10 @@ int key_import_export_sym(yaca_key_h sym) /* RAW */ ret = yaca_key_export(sym, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL, &raw, &raw_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&raw_imported, YACA_KEY_TYPE_SYMMETRIC, NULL, raw, raw_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(raw, raw_len, "\n\t***** RAW exported key: *****"); @@ -77,12 +77,12 @@ int key_import_export_sym(yaca_key_h sym) raw = NULL; ret = yaca_key_export(raw_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL, &raw, &raw_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(raw, raw_len, "\t***** RAW imported key: *****"); - ret = 0; + ret = YACA_ERROR_NONE; free: yaca_key_free(raw_imported); @@ -118,10 +118,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* PEM private */ ret = yaca_key_export(priv, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_prv, &pem_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_key_import(&pem_prv_imported, priv_type, NULL, pem_prv, pem_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** %s PEM exported private key: *****\n%.*s", algo, (int)pem_prv_len, pem_prv); @@ -129,7 +129,7 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, pem_prv = NULL; ret = yaca_key_export(pem_prv_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_prv, &pem_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***** %s PEM imported private key: *****\n%.*s", algo, (int)pem_prv_len, pem_prv); @@ -138,10 +138,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* DER private */ ret = yaca_key_export(priv, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_prv, &der_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&der_prv_imported, priv_type, NULL, der_prv, der_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_prv, der_prv_len, "\n\t***** %s DER exported private key: *****", algo); @@ -149,7 +149,7 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, der_prv = NULL; ret = yaca_key_export(der_prv_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_prv, &der_prv_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_prv, der_prv_len, "\t***** %s DER imported private key: *****", algo); @@ -158,10 +158,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* PEM public */ ret = yaca_key_export(pub, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_pub, &pem_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&pem_pub_imported, pub_type, NULL, pem_pub, pem_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** %s PEM exported public key: *****\n%.*s", algo, (int)pem_pub_len, pem_pub); @@ -169,7 +169,7 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, pem_pub = NULL; ret = yaca_key_export(pem_pub_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pem_pub, &pem_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***** %s PEM imported public key: *****\n%.*s", algo, (int)pem_pub_len, pem_pub); @@ -178,10 +178,10 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, /* DER public */ ret = yaca_key_export(pub, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_pub, &der_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_import(&der_pub_imported, pub_type, NULL, der_pub, der_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_pub, der_pub_len, "\n\t***** %s DER exported public key: *****", algo); @@ -189,12 +189,12 @@ int key_import_export_asym(yaca_key_h priv, yaca_key_h pub, der_pub = NULL; ret = yaca_key_export(der_pub_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL, &der_pub, &der_pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; dump_hex(der_pub, der_pub_len, "\t***** %s DER imported public key: *****", algo); - ret = 0; + ret = YACA_ERROR_NONE; free: yaca_key_free(der_pub_imported); @@ -217,7 +217,7 @@ int key_import_x509(void) yaca_key_h rsa_pub_from_cert = YACA_KEY_NULL; ret = read_file("x509.crt", &pub, &pub_len); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { printf("Make sure you copied a x509.crt from yaca_root/examples to your current directory\n"); printf("You can also generate one with:\n"); printf("openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout x509.key -out x509.crt\n"); @@ -225,19 +225,19 @@ int key_import_x509(void) } ret = yaca_key_import(&rsa_pub_from_cert, YACA_KEY_TYPE_RSA_PUB, NULL, pub, pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; yaca_free(pub); pub = NULL; ret = yaca_key_export(rsa_pub_from_cert, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &pub, &pub_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\n\t***** RSA X509 imported public key: *****\n%.*s", (int)pub_len, pub); - ret = 0; + ret = YACA_ERROR_NONE; free: yaca_key_free(rsa_pub_from_cert); @@ -255,36 +255,36 @@ int main() int ret; ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; yaca_debug_set_error_cb(debug_func); ret = yaca_key_gen(&sym, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_gen(&rsa_priv, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_extract_public(rsa_priv, &rsa_pub); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_gen(&dsa_priv, YACA_KEY_TYPE_DSA_PRIV, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; ret = yaca_key_extract_public(dsa_priv, &dsa_pub); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; printf("\t***************************************\n"); printf("\t************** SYMMETRIC **************\n"); printf("\t***************************************\n"); ret = key_import_export_sym(sym); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t********* SYMMETRIC - success *********\n\n"); else printf("\n\t********* SYMMETRIC - failure *********\n\n"); @@ -293,7 +293,7 @@ int main() printf("\t***************** RSA *****************\n"); printf("\t***************************************\n"); ret = key_import_export_asym(rsa_priv, rsa_pub, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_TYPE_RSA_PUB, "RSA"); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t************ RSA - success ************\n\n"); else printf("\n\t************ RSA - failure ************\n\n"); @@ -302,7 +302,7 @@ int main() printf("\t***************** DSA *****************\n"); printf("\t***************************************\n"); ret = key_import_export_asym(dsa_priv, dsa_pub, YACA_KEY_TYPE_DSA_PRIV, YACA_KEY_TYPE_DSA_PUB, "DSA"); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t************ DSA - success ************\n\n"); else printf("\n\t************ DSA - failure ************\n\n"); @@ -311,7 +311,7 @@ int main() printf("\t**************** X509 *****************\n"); printf("\t***************************************\n"); ret = key_import_x509(); - if (ret == 0) + if (ret == YACA_ERROR_NONE) printf("\n\t*********** X509 - success ************\n\n"); else printf("\n\t*********** X509 - failure ************\n\n"); diff --git a/examples/key_password.c b/examples/key_password.c index d76f195..5a79e15 100644 --- a/examples/key_password.c +++ b/examples/key_password.c @@ -37,19 +37,19 @@ int main(int argc, char* argv[]) char *password = NULL; ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_gen(&key, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_1024BIT); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = read_stdin_line("encryption pass: ", &password); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_export(key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, password, &k, &kl); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; yaca_free(password); @@ -60,7 +60,7 @@ int main(int argc, char* argv[]) ret = yaca_key_import(&key, YACA_KEY_TYPE_RSA_PRIV, NULL, k, kl); if (ret == YACA_ERROR_PASSWORD_INVALID) { ret = read_stdin_line("decryption pass: ", &password); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; ret = yaca_key_import(&key, YACA_KEY_TYPE_RSA_PRIV, password, k, kl); @@ -71,14 +71,14 @@ int main(int argc, char* argv[]) password = NULL; } - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; yaca_free(k); k = NULL; ret = yaca_key_export(key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL, &k, &kl); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto exit; printf("%.*s", (int)kl, k); @@ -90,5 +90,5 @@ exit: yaca_exit(); - return 0; + return YACA_ERROR_NONE; } diff --git a/examples/seal.c b/examples/seal.c index a2359a7..586874e 100644 --- a/examples/seal.c +++ b/examples/seal.c @@ -56,21 +56,21 @@ void encrypt_seal(void) printf("Plain data (16 of %zu bytes): %.16s\n", LOREM4096_SIZE, lorem4096); /* Generate key pair */ - if (yaca_key_gen(&key_priv, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_4096BIT) != 0) + if (yaca_key_gen(&key_priv, YACA_KEY_TYPE_RSA_PRIV, YACA_KEY_4096BIT) != YACA_ERROR_NONE) return; - if (yaca_key_extract_public(key_priv, &key_pub) != 0) + if (yaca_key_extract_public(key_priv, &key_pub) != YACA_ERROR_NONE) goto ex_prvk; /* Encrypt a.k.a. seal */ { - if (yaca_seal_init(&ctx, key_pub, algo, bcm, key_bits, &aes_key, &iv) != 0) + if (yaca_seal_init(&ctx, key_pub, algo, bcm, key_bits, &aes_key, &iv) != YACA_ERROR_NONE) goto ex_pubk; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_ak; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_ak; /* Calculate max output: size of update + final chunks */ @@ -80,11 +80,11 @@ void encrypt_seal(void) /* Seal and finalize */ out_size = enc_size; - if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != 0) + if (yaca_seal_update(ctx, lorem4096, LOREM4096_SIZE, enc, &out_size) != YACA_ERROR_NONE) goto ex_of; rem = enc_size - out_size; - if (yaca_seal_final(ctx, enc + out_size, &rem) != 0) + if (yaca_seal_final(ctx, enc + out_size, &rem) != YACA_ERROR_NONE) goto ex_of; enc_size = rem + out_size; @@ -97,13 +97,13 @@ void encrypt_seal(void) /* Decrypt a.k.a. open */ { - if (yaca_open_init(&ctx, key_priv, algo, bcm, key_bits, aes_key, iv) != 0) + if (yaca_open_init(&ctx, key_priv, algo, bcm, key_bits, aes_key, iv) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_block_length(ctx, &block_len) != 0) + if (yaca_get_block_length(ctx, &block_len) != YACA_ERROR_NONE) goto ex_of; - if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != 0) + if (yaca_get_output_length(ctx, LOREM4096_SIZE, &output_len) != YACA_ERROR_NONE) goto ex_of; /* Calculate max output: size of update + final chunks */ @@ -113,11 +113,11 @@ void encrypt_seal(void) /* Open and finalize */ out_size = dec_size; - if (yaca_open_update(ctx, enc, enc_size, dec, &out_size) != 0) + if (yaca_open_update(ctx, enc, enc_size, dec, &out_size) != YACA_ERROR_NONE) goto ex_in; rem = dec_size - out_size; - if (yaca_open_final(ctx, dec + out_size, &rem) != 0) + if (yaca_open_final(ctx, dec + out_size, &rem) != YACA_ERROR_NONE) goto ex_in; dec_size = rem + out_size; @@ -144,7 +144,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; encrypt_seal(); diff --git a/examples/sign.c b/examples/sign.c index 48f6dca..d5f65d6 100644 --- a/examples/sign.c +++ b/examples/sign.c @@ -43,10 +43,10 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo) yaca_key_h pub = YACA_KEY_NULL; // GENERATE - if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != 0) + if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != YACA_ERROR_NONE) return; - if (yaca_key_extract_public(prv, &pub) != 0) + if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE) goto finish; // SIGN @@ -55,7 +55,7 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo) lorem4096, LOREM4096_SIZE, &signature, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature, signature_len, "[Simple API] %s Signature of lorem4096:", algo); @@ -66,7 +66,7 @@ void simple_sign_verify_asym(yaca_key_type_e type, const char *algo) lorem4096, LOREM4096_SIZE, signature, - signature_len) != 0) + signature_len) != YACA_ERROR_NONE) printf("[Simple API] %s verification failed\n", algo); else printf("[Simple API] %s verification succesful\n", algo); @@ -86,7 +86,7 @@ void simple_sign_verify_hmac(void) yaca_key_h key = YACA_KEY_NULL; // GENERATE - if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != 0) + if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != YACA_ERROR_NONE) return; // SIGN @@ -95,7 +95,7 @@ void simple_sign_verify_hmac(void) lorem4096, LOREM4096_SIZE, &signature1, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature1, signature_len, "[Simple API] HMAC Signature of lorem4096:"); @@ -106,10 +106,10 @@ void simple_sign_verify_hmac(void) lorem4096, LOREM4096_SIZE, &signature2, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Simple API] HMAC verification failed\n"); else printf("[Simple API] HMAC verification succesful\n"); @@ -138,7 +138,7 @@ void simple_sign_verify_cmac(void) lorem4096, LOREM4096_SIZE, &signature1, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature1, signature_len, "[Simple API] CMAC Signature of lorem4096:"); @@ -150,10 +150,10 @@ void simple_sign_verify_cmac(void) lorem4096, LOREM4096_SIZE, &signature2, - &signature_len) != 0) + &signature_len) != YACA_ERROR_NONE) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Simple API] CMAC verification failed\n"); else printf("[Simple API] CMAC verification succesful\n"); @@ -176,29 +176,29 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo) yaca_padding_e padding = YACA_PADDING_PKCS1_PSS; // GENERATE - if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != 0) + if (yaca_key_gen(&prv, type, YACA_KEY_1024BIT) != YACA_ERROR_NONE) return; - if (yaca_key_extract_public(prv, &pub) != 0) + if (yaca_key_extract_public(prv, &pub) != YACA_ERROR_NONE) goto finish; // SIGN - if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, prv) != 0) + if (yaca_sign_init(&ctx, YACA_DIGEST_SHA512, prv) != YACA_ERROR_NONE) goto finish; - if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE) goto finish; - if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature = yaca_malloc(signature_len)) == NULL) goto finish; - if (yaca_sign_final(ctx, signature, &signature_len) != 0) + if (yaca_sign_final(ctx, signature, &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature, signature_len, "[Advanced API] %s Signature of lorem4096:", algo); @@ -208,16 +208,16 @@ void sign_verify_asym(yaca_key_type_e type, const char *algo) ctx = YACA_CTX_NULL; // VERIFY - if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, pub) != 0) + if (yaca_verify_init(&ctx, YACA_DIGEST_SHA512, pub) != YACA_ERROR_NONE) goto finish; - if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != 0) + if (yaca_ctx_set_param(ctx, YACA_PARAM_PADDING, (char*)(&padding), sizeof(padding)) != YACA_ERROR_NONE) goto finish; - if (yaca_verify_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_verify_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_verify_final(ctx, signature, signature_len) != 0) + if (yaca_verify_final(ctx, signature, signature_len) != YACA_ERROR_NONE) printf("[Advanced API] %s verification failed\n", algo); else printf("[Advanced API] %s verification succesful\n", algo); @@ -239,23 +239,23 @@ void sign_verify_hmac(void) yaca_key_h key = YACA_KEY_NULL; // GENERATE - if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != 0) + if (yaca_key_gen(&key, YACA_KEY_TYPE_SYMMETRIC, YACA_KEY_256BIT) != YACA_ERROR_NONE) return; // SIGN - if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != 0) + if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE) goto finish; - if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature1 = yaca_malloc(signature_len)) == NULL) goto finish; - if (yaca_sign_final(ctx, signature1, &signature_len) != 0) + if (yaca_sign_final(ctx, signature1, &signature_len) != YACA_ERROR_NONE) goto finish; dump_hex(signature1, signature_len, "[Advanced API] HMAC Signature of lorem4096:"); @@ -265,22 +265,22 @@ void sign_verify_hmac(void) ctx = YACA_CTX_NULL; // VERIFY - if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != 0) + if (yaca_sign_hmac_init(&ctx, YACA_DIGEST_SHA512, key) != YACA_ERROR_NONE) goto finish; - if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != 0) + if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE) != YACA_ERROR_NONE) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature2 = yaca_malloc(signature_len)) == NULL) goto finish; - if (yaca_sign_final(ctx, signature2, &signature_len) != 0) + if (yaca_sign_final(ctx, signature2, &signature_len) != YACA_ERROR_NONE) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Advanced API] HMAC verification failed\n"); else printf("[Advanced API] HMAC verification succesful\n"); @@ -306,13 +306,13 @@ void sign_verify_cmac(void) return; // SIGN - if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != 0) + if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != YACA_ERROR_NONE) goto finish; if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE)) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature1 = yaca_malloc(signature_len)) == NULL) @@ -328,13 +328,13 @@ void sign_verify_cmac(void) ctx = YACA_CTX_NULL; // VERIFY - if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != 0) + if (yaca_sign_cmac_init(&ctx, YACA_ENC_AES, key) != YACA_ERROR_NONE) goto finish; if (yaca_sign_update(ctx, lorem4096, LOREM4096_SIZE)) goto finish; - if (yaca_get_sign_length(ctx, &signature_len) != 0) + if (yaca_get_sign_length(ctx, &signature_len) != YACA_ERROR_NONE) goto finish; if ((signature2 = yaca_malloc(signature_len)) == NULL) @@ -343,7 +343,7 @@ void sign_verify_cmac(void) if (yaca_sign_final(ctx, signature2, &signature_len)) goto finish; - if (yaca_memcmp(signature1, signature2, signature_len) != 0) + if (yaca_memcmp(signature1, signature2, signature_len) != YACA_ERROR_NONE) printf("[Advanced API] CMAC verification failed\n"); else printf("[Advanced API] CMAC verification succesful\n"); @@ -360,7 +360,7 @@ int main() yaca_debug_set_error_cb(debug_func); int ret = yaca_init(); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; simple_sign_verify_asym(YACA_KEY_TYPE_RSA_PRIV, "RSA"); diff --git a/src/crypto.c b/src/crypto.c index c0ce1f4..3622579 100644 --- a/src/crypto.c +++ b/src/crypto.c @@ -84,7 +84,7 @@ API int yaca_init(void) for (int i = 0; i < CRYPTO_num_locks(); i++) { if (pthread_mutex_init(&mutexes[i], NULL) != 0) { - int ret = 0; + int ret = YACA_ERROR_NONE; switch (errno) { case ENOMEM: ret = YACA_ERROR_OUT_OF_MEMORY; @@ -112,7 +112,7 @@ API int yaca_init(void) We should also initialize the entropy for random number generator: https://wiki.openssl.org/index.php/Random_Numbers#Initialization */ - return 0; + return YACA_ERROR_NONE; } API void yaca_exit(void) @@ -166,7 +166,7 @@ API int yaca_rand_bytes(char *data, size_t data_len) return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param, @@ -207,7 +207,7 @@ API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *o API int yaca_memcmp(const void *first, const void *second, size_t len) { if (CRYPTO_memcmp(first, second, len) == 0) - return 0; + return YACA_ERROR_NONE; return YACA_ERROR_DATA_MISMATCH; } diff --git a/src/digest.c b/src/digest.c index a7e9bbe..5bb6883 100644 --- a/src/digest.c +++ b/src/digest.c @@ -60,7 +60,7 @@ static int get_digest_output_length(const yaca_ctx_h ctx, size_t input_len, size return YACA_ERROR_INVALID_ARGUMENT; *output_len = EVP_MD_CTX_size(c->mdctx); - return 0; + return YACA_ERROR_NONE; } static void destroy_digest_context(yaca_ctx_h ctx) @@ -76,7 +76,7 @@ static void destroy_digest_context(yaca_ctx_h ctx) int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md) { - int ret = 0; + int ret = YACA_ERROR_NONE; if (!md) return YACA_ERROR_INVALID_ARGUMENT; @@ -108,7 +108,7 @@ int digest_get_algorithm(yaca_digest_algo_e algo, const EVP_MD **md) break; } - if (ret == 0 && *md == NULL) { + if (ret == YACA_ERROR_NONE && *md == NULL) { ret = YACA_ERROR_INTERNAL; ERROR_DUMP(ret); } @@ -134,7 +134,7 @@ API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo) nc->ctx.get_output_length = get_digest_output_length; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free; nc->mdctx = EVP_MD_CTX_create(); @@ -153,7 +153,7 @@ API int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo) *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; ctx: EVP_MD_CTX_destroy(nc->mdctx); @@ -177,7 +177,7 @@ API int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len) return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len) @@ -201,5 +201,5 @@ API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len) *digest_len = len; - return 0; + return YACA_ERROR_NONE; } diff --git a/src/encrypt.c b/src/encrypt.c index c059c7e..3d83b78 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -96,7 +96,7 @@ static int get_encrypt_output_length(const yaca_ctx_h ctx, size_t input_len, siz *output_len = block_size; } - return 0; + return YACA_ERROR_NONE; } static int set_encrypt_param(yaca_ctx_h ctx, @@ -153,7 +153,7 @@ static int set_encrypt_param(yaca_ctx_h ctx, default: return YACA_ERROR_INVALID_ARGUMENT; } - return 0; + return YACA_ERROR_NONE; } static int get_encrypt_param(const yaca_ctx_h ctx, @@ -197,7 +197,7 @@ static int get_encrypt_param(const yaca_ctx_h ctx, return YACA_ERROR_INVALID_ARGUMENT; break; } - return 0; + return YACA_ERROR_NONE; } static const char *encrypt_algo_to_str(yaca_enc_algo_e algo) @@ -309,7 +309,7 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, } *cipher = lcipher; - return 0; + return YACA_ERROR_NONE; } static int encrypt_init(yaca_ctx_h *ctx, @@ -349,11 +349,11 @@ static int encrypt_init(yaca_ctx_h *ctx, nc->tag_len = 0; ret = yaca_key_get_bits(sym_key, &key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; ret = encrypt_get_algorithm(algo, bcm, key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; ret = EVP_CIPHER_iv_length(cipher); @@ -376,7 +376,7 @@ static int encrypt_init(yaca_ctx_h *ctx, goto err_free; } ret = yaca_key_get_bits(iv, &iv_bits_check); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { ret = YACA_ERROR_INVALID_ARGUMENT; goto err_free; } @@ -463,7 +463,7 @@ static int encrypt_init(yaca_ctx_h *ctx, } *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; err_ctx: EVP_CIPHER_CTX_free(nc->cipher_ctx); @@ -508,7 +508,7 @@ static int encrypt_update(yaca_ctx_h ctx, } *output_len = loutput_len; - return 0; + return YACA_ERROR_NONE; } static int encrypt_final(yaca_ctx_h ctx, @@ -544,7 +544,7 @@ static int encrypt_final(yaca_ctx_h ctx, } *output_len = loutput_len; - return 0; + return YACA_ERROR_NONE; } API int yaca_get_iv_bits(yaca_enc_algo_e algo, @@ -556,7 +556,7 @@ API int yaca_get_iv_bits(yaca_enc_algo_e algo, int ret; ret = encrypt_get_algorithm(algo, bcm, key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = EVP_CIPHER_iv_length(cipher); @@ -566,7 +566,7 @@ API int yaca_get_iv_bits(yaca_enc_algo_e algo, } *iv_bits = ret * 8; - return 0; + return YACA_ERROR_NONE; } API int yaca_encrypt_init(yaca_ctx_h *ctx, diff --git a/src/key.c b/src/key.c index dd4e648..b3e2c07 100755 --- a/src/key.c +++ b/src/key.c @@ -71,7 +71,7 @@ int base64_decode_length(const char *data, size_t data_len, size_t *len) } *len = data_len / 4 * 3 - padded; - return 0; + return YACA_ERROR_NONE; } #define TMP_BUF_LEN 512 @@ -97,7 +97,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) /* First phase of correctness checking, calculate expected output length */ ret = base64_decode_length(data, data_len, &b64_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; b64 = BIO_new(BIO_f_base64()); @@ -134,7 +134,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) goto free_bio; } - if (ret == 0) + if (ret == YACA_ERROR_NONE) break; if (BIO_write(dst, tmpbuf, ret) != ret) { @@ -160,7 +160,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) *output = dst; dst = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free_bio: BIO_free_all(b64); @@ -185,7 +185,7 @@ int import_simple(yaca_key_h *key, struct yaca_key_simple_s *nk = NULL; ret = base64_decode(data, data_len, &decoded); - if (ret == 0) { + if (ret == YACA_ERROR_NONE) { /* Conversion successfull, get the BASE64 */ long len = BIO_get_mem_data(decoded, &key_data); if (len <= 0 || key_data == NULL) { @@ -230,7 +230,7 @@ int import_simple(yaca_key_h *key, nk->key.type = key_type; *key = (yaca_key_h)nk; - ret = 0; + ret = YACA_ERROR_NONE; out: BIO_free_all(decoded); @@ -381,7 +381,7 @@ int import_evp(yaca_key_h *key, (*key)->type = type; pkey = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free: EVP_PKEY_free(pkey); @@ -407,7 +407,7 @@ int export_simple_raw(struct yaca_key_simple_s *simple_key, memcpy(*data, simple_key->d, key_len); *data_len = key_len; - return 0; + return YACA_ERROR_NONE; } int export_simple_base64(struct yaca_key_simple_s *simple_key, @@ -472,7 +472,7 @@ int export_simple_base64(struct yaca_key_simple_s *simple_key, memcpy(*data, bio_data, bio_data_len); *data_len = bio_data_len; - ret = 0; + ret = YACA_ERROR_NONE; free_bio: BIO_free_all(b64); @@ -491,7 +491,7 @@ int export_evp(struct yaca_key_evp_s *evp_key, assert(data != NULL); assert(data_len != NULL); - int ret = 0; + int ret = YACA_ERROR_NONE; BIO *mem; const EVP_CIPHER *enc = NULL; char *bio_data; @@ -604,7 +604,7 @@ int export_evp(struct yaca_key_evp_s *evp_key, memcpy(*data, bio_data, bio_data_len); *data_len = bio_data_len; - ret = 0; + ret = YACA_ERROR_NONE; free_bio: BIO_free_all(mem); @@ -629,11 +629,11 @@ int gen_simple(struct yaca_key_simple_s **out, size_t key_bits) nk->bits = key_bits; ret = yaca_rand_bytes(nk->d, key_byte_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; *out = nk; - return 0; + return YACA_ERROR_NONE; } int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits) @@ -675,7 +675,7 @@ int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits) nk->bits = key_bits; *out = nk; - return 0; + return YACA_ERROR_NONE; free_nk: yaca_free(nk); @@ -731,7 +731,7 @@ int gen_evp_rsa(struct yaca_key_evp_s **out, size_t key_bits) *out = nk; nk = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free_ctx: EVP_PKEY_CTX_free(ctx); @@ -811,7 +811,7 @@ int gen_evp_dsa(struct yaca_key_evp_s **out, size_t key_bits) *out = nk; nk = NULL; - ret = 0; + ret = YACA_ERROR_NONE; free_kctx: EVP_PKEY_CTX_free(kctx); @@ -882,7 +882,7 @@ API int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type) return YACA_ERROR_INVALID_ARGUMENT; *key_type = lkey->type; - return 0; + return YACA_ERROR_NONE; } API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits) @@ -895,7 +895,7 @@ API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits) if (simple_key != NULL) { *key_bits = simple_key->bits; - return 0; + return YACA_ERROR_NONE; } if (evp_key != NULL) { @@ -910,7 +910,7 @@ API int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits) } *key_bits = ret; - return 0; + return YACA_ERROR_NONE; } return YACA_ERROR_INVALID_ARGUMENT; @@ -1009,43 +1009,43 @@ API int yaca_key_gen(yaca_key_h *key, case YACA_KEY_TYPE_SYMMETRIC: case YACA_KEY_TYPE_IV: ret = gen_simple(&nk_simple, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_simple->key.type = key_type; *key = (yaca_key_h)nk_simple; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_DES: ret = gen_simple_des(&nk_simple, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_simple->key.type = key_type; *key = (yaca_key_h)nk_simple; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_RSA_PRIV: ret = gen_evp_rsa(&nk_evp, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_evp->key.type = key_type; *key = (yaca_key_h)nk_evp; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_DSA_PRIV: ret = gen_evp_dsa(&nk_evp, key_bits); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk_evp->key.type = key_type; *key = (yaca_key_h)nk_evp; - return 0; + return YACA_ERROR_NONE; case YACA_KEY_TYPE_DH_PRIV: case YACA_KEY_TYPE_EC_PRIV: @@ -1113,7 +1113,7 @@ API int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key) goto free_pkey; } - return 0; + return YACA_ERROR_NONE; free_pkey: EVP_PKEY_free(pkey); @@ -1179,7 +1179,7 @@ API int yaca_key_derive_pbkdf2(const char *password, return YACA_ERROR_TOO_BIG_ARGUMENT; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len); @@ -1199,7 +1199,7 @@ API int yaca_key_derive_pbkdf2(const char *password, } *key = (yaca_key_h)nk; - return 0; + return YACA_ERROR_NONE; err: yaca_free(nk); return ret; diff --git a/src/seal.c b/src/seal.c index 1dc583e..c17cc5d 100644 --- a/src/seal.c +++ b/src/seal.c @@ -95,7 +95,7 @@ static int get_seal_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *output_len = block_size; } - return 0; + return YACA_ERROR_NONE; } static int seal_init(yaca_ctx_h *ctx, @@ -154,7 +154,7 @@ static int seal_init(yaca_ctx_h *ctx, } ret = encrypt_get_algorithm(algo, bcm, sym_key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_key; ret = EVP_CIPHER_iv_length(cipher); @@ -198,7 +198,7 @@ static int seal_init(yaca_ctx_h *ctx, *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; err_iv: yaca_free(liv); @@ -250,7 +250,7 @@ static int open_init(yaca_ctx_h *ctx, nc->op_type = OP_OPEN; ret = encrypt_get_algorithm(algo, bcm, sym_key_bits, &cipher); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; ret = EVP_CIPHER_iv_length(cipher); @@ -275,7 +275,7 @@ static int open_init(yaca_ctx_h *ctx, // TODO: handling of algorithms with variable IV length ret = yaca_key_get_bits(iv, &iv_bits_check); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { ret = YACA_ERROR_INVALID_ARGUMENT; goto err_free; } @@ -303,7 +303,7 @@ static int open_init(yaca_ctx_h *ctx, } *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; err_ctx: EVP_CIPHER_CTX_free(nc->cipher_ctx); @@ -343,7 +343,7 @@ static int seal_update(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } static int seal_final(yaca_ctx_h ctx, @@ -374,7 +374,7 @@ static int seal_final(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_seal_init(yaca_ctx_h *ctx, diff --git a/src/sign.c b/src/sign.c index bc9b137..6b76062 100644 --- a/src/sign.c +++ b/src/sign.c @@ -92,7 +92,7 @@ static int get_sign_output_length(const yaca_ctx_h ctx, } *output_len = len; - return 0; + return YACA_ERROR_NONE; } static void destroy_sign_context(yaca_ctx_h ctx) @@ -165,7 +165,7 @@ int set_sign_param(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } int get_sign_param(const yaca_ctx_h ctx, @@ -232,7 +232,7 @@ int get_sign_param(const yaca_ctx_h ctx, memcpy(*value, &padding, sizeof(yaca_padding_e)); *value_len = sizeof(yaca_padding_e); - return 0; + return YACA_ERROR_NONE; } API int yaca_sign_init(yaca_ctx_h *ctx, @@ -271,7 +271,7 @@ API int yaca_sign_init(yaca_ctx_h *ctx, nc->ctx.get_param = get_sign_param; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_ctx; nc->mdctx = EVP_MD_CTX_create(); @@ -290,7 +290,7 @@ API int yaca_sign_init(yaca_ctx_h *ctx, *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_ctx: yaca_ctx_free((yaca_ctx_h)nc); @@ -333,7 +333,7 @@ API int yaca_sign_hmac_init(yaca_ctx_h *ctx, } ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_pkey; nc->mdctx = EVP_MD_CTX_create(); @@ -351,7 +351,7 @@ API int yaca_sign_hmac_init(yaca_ctx_h *ctx, } *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_pkey: EVP_PKEY_free(pkey); @@ -387,7 +387,7 @@ API int yaca_sign_cmac_init(yaca_ctx_h *ctx, nc->ctx.get_output_length = get_sign_output_length; ret = encrypt_get_algorithm(algo, YACA_BCM_CBC, simple_key->bits, &cipher); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { goto free_ctx; } @@ -436,7 +436,7 @@ API int yaca_sign_cmac_init(yaca_ctx_h *ctx, // TODO refactor error handling: set mdctx to NULL, set pkey to NULL *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_pkey: EVP_PKEY_free(pkey); @@ -466,7 +466,7 @@ API int yaca_sign_update(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_sign_final(yaca_ctx_h ctx, @@ -487,7 +487,7 @@ API int yaca_sign_final(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_verify_init(yaca_ctx_h *ctx, @@ -525,7 +525,7 @@ API int yaca_verify_init(yaca_ctx_h *ctx, nc->ctx.get_param = get_sign_param; ret = digest_get_algorithm(algo, &md); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_ctx; nc->mdctx = EVP_MD_CTX_create(); @@ -544,7 +544,7 @@ API int yaca_verify_init(yaca_ctx_h *ctx, *ctx = (yaca_ctx_h)nc; - return 0; + return YACA_ERROR_NONE; free_ctx: yaca_ctx_free((yaca_ctx_h)nc); @@ -569,7 +569,7 @@ API int yaca_verify_update(yaca_ctx_h ctx, return ret; } - return 0; + return YACA_ERROR_NONE; } API int yaca_verify_final(yaca_ctx_h ctx, @@ -587,9 +587,9 @@ API int yaca_verify_final(yaca_ctx_h ctx, signature_len); if (ret == 1) - return 0; + return YACA_ERROR_NONE; - if (ret == 0) { + if (ret == YACA_ERROR_NONE) { ERROR_CLEAR(); return YACA_ERROR_DATA_MISMATCH; } diff --git a/src/simple.c b/src/simple.c index 04db0fa..3ba93f8 100644 --- a/src/simple.c +++ b/src/simple.c @@ -48,15 +48,15 @@ API int yaca_digest_calc(yaca_digest_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_digest_init(&ctx, algo); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_digest_update(ctx, data, data_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ret = yaca_get_digest_length(ctx, &ldigest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ldigest = yaca_malloc(ldigest_len); @@ -64,14 +64,14 @@ API int yaca_digest_calc(yaca_digest_algo_e algo, goto err; ret = yaca_digest_final(ctx, ldigest, &ldigest_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; yaca_ctx_free(ctx); *digest_len = ldigest_len; *digest = ldigest; - return 0; + return YACA_ERROR_NONE; err_free: yaca_free(ldigest); @@ -100,15 +100,15 @@ API int yaca_encrypt(yaca_enc_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_encrypt_init(&ctx, algo, bcm, sym_key, iv); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_get_block_length(ctx, &lcipher_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ret = yaca_get_output_length(ctx, plain_len, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; if (out_len > SIZE_MAX - lcipher_len) { @@ -124,7 +124,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, out_len = lcipher_len; ret = yaca_encrypt_update(ctx, plain, plain_len, lcipher, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; assert (out_len <= lcipher_len); @@ -132,7 +132,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, written = out_len; out_len = lcipher_len - written; ret = yaca_encrypt_final(ctx, lcipher + written, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; written += out_len; @@ -148,7 +148,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, *cipher = rcipher; *cipher_len = written; - return 0; + return YACA_ERROR_NONE; err_free: yaca_free(lcipher); @@ -177,15 +177,15 @@ API int yaca_decrypt(yaca_enc_algo_e algo, return YACA_ERROR_INVALID_ARGUMENT; ret = yaca_decrypt_init(&ctx, algo, bcm, sym_key, iv); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_get_block_length(ctx, &lplain_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; ret = yaca_get_output_length(ctx, cipher_len, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err; if (out_len > SIZE_MAX - lplain_len) { @@ -201,7 +201,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, out_len = lplain_len; ret = yaca_decrypt_update(ctx, cipher, cipher_len, lplain, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; assert(out_len <= lplain_len); @@ -209,7 +209,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, written = out_len; out_len = lplain_len - written; ret = yaca_decrypt_final(ctx, lplain + written, &out_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto err_free; written += out_len; @@ -225,7 +225,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, *plain = rplain; *plain_len = written; - return 0; + return YACA_ERROR_NONE; err_free: yaca_free(lplain); @@ -243,11 +243,11 @@ static int sign(const yaca_ctx_h ctx, const char *data, size_t data_len, assert(signature_len != NULL); ret = yaca_sign_update(ctx, data, data_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_get_sign_length(ctx, signature_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; *signature = yaca_malloc(*signature_len); @@ -255,7 +255,7 @@ static int sign(const yaca_ctx_h ctx, const char *data, size_t data_len, return YACA_ERROR_OUT_OF_MEMORY; ret = yaca_sign_final(ctx, *signature, signature_len); - if (ret != 0) { + if (ret != YACA_ERROR_NONE) { yaca_free(*signature); *signature = NULL; } @@ -274,7 +274,7 @@ API int yaca_sign(yaca_digest_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_sign_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = sign(ctx, data, data_len, signature, signature_len); @@ -295,11 +295,11 @@ API int yaca_verify(yaca_digest_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_verify_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = yaca_verify_update(ctx, data, data_len); - if (ret != 0) + if (ret != YACA_ERROR_NONE) goto free_ctx; ret = yaca_verify_final(ctx, signature, signature_len); @@ -321,7 +321,7 @@ API int yaca_hmac(yaca_digest_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_sign_hmac_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = sign(ctx, data, data_len, mac, mac_len); @@ -342,7 +342,7 @@ API int yaca_cmac(yaca_enc_algo_e algo, yaca_ctx_h ctx = YACA_CTX_NULL; ret = yaca_sign_cmac_init(&ctx, algo, key); - if (ret != 0) + if (ret != YACA_ERROR_NONE) return ret; ret = sign(ctx, data, data_len, mac, mac_len); -- 2.7.4 From bf9cd01f64e2cccf90ca9a42ff210120eb2a18b3 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 27 May 2016 13:45:33 +0200 Subject: [PATCH 04/16] Add yaca_error_e typedef. Change-Id: I5bf5e9ad7cc91df53cbb437044d31dd8a7e1efad --- api/yaca/yaca_error.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/yaca/yaca_error.h b/api/yaca/yaca_error.h index 26f1979..17c1f30 100755 --- a/api/yaca/yaca_error.h +++ b/api/yaca/yaca_error.h @@ -44,7 +44,7 @@ extern "C" { * * @since_tizen 3.0 */ -enum __yaca_error_code { +typedef enum { YACA_ERROR_NONE = TIZEN_ERROR_NONE, YACA_ERROR_INVALID_ARGUMENT = TIZEN_ERROR_INVALID_PARAMETER, @@ -54,7 +54,7 @@ enum __yaca_error_code { YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_YACA | 0x04, YACA_ERROR_DATA_MISMATCH = TIZEN_ERROR_YACA | 0x05, YACA_ERROR_PASSWORD_INVALID = TIZEN_ERROR_YACA | 0x06 -}; +} yaca_error_e; /**@}*/ -- 2.7.4 From e30b55d0522b8a9d51e9ab89aae301ea3b454c45 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 27 May 2016 15:27:46 +0200 Subject: [PATCH 05/16] Remove YACA_ERROR_NOT_IMPLEMENTED Change-Id: If8361e25c012984d3ebfaf7ae03df5964140f230 --- api/yaca/yaca_error.h | 1 - src/encrypt.c | 3 ++- src/key.c | 23 +++++++++++------------ src/sign.c | 4 ++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/api/yaca/yaca_error.h b/api/yaca/yaca_error.h index 17c1f30..5bcfec7 100755 --- a/api/yaca/yaca_error.h +++ b/api/yaca/yaca_error.h @@ -48,7 +48,6 @@ typedef enum { YACA_ERROR_NONE = TIZEN_ERROR_NONE, YACA_ERROR_INVALID_ARGUMENT = TIZEN_ERROR_INVALID_PARAMETER, - YACA_ERROR_NOT_IMPLEMENTED = TIZEN_ERROR_YACA | 0x01, YACA_ERROR_INTERNAL = TIZEN_ERROR_YACA | 0x02, YACA_ERROR_TOO_BIG_ARGUMENT = TIZEN_ERROR_YACA | 0x03, YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_YACA | 0x04, diff --git a/src/encrypt.c b/src/encrypt.c index 3d83b78..dc1a1b3 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -292,8 +292,9 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, ret = snprintf(cipher_name, sizeof(cipher_name), "%s", algo_name); break; case YACA_ENC_UNSAFE_SKIPJACK: + //TODO NOT_IMPLEMENTED default: - return YACA_ERROR_NOT_IMPLEMENTED; + return YACA_ERROR_INVALID_ARGUMENT; } if (ret < 0) diff --git a/src/key.c b/src/key.c index b3e2c07..a0e771a 100755 --- a/src/key.c +++ b/src/key.c @@ -530,9 +530,7 @@ int export_evp(struct yaca_key_evp_s *evp_key, case YACA_KEY_TYPE_DH_PUB: case YACA_KEY_TYPE_EC_PRIV: case YACA_KEY_TYPE_EC_PUB: - ret = YACA_ERROR_NOT_IMPLEMENTED; - goto free_bio; - + //TODO NOT_IMPLEMENTED default: ret = YACA_ERROR_INVALID_ARGUMENT; goto free_bio; @@ -560,9 +558,7 @@ int export_evp(struct yaca_key_evp_s *evp_key, case YACA_KEY_TYPE_DH_PUB: case YACA_KEY_TYPE_EC_PRIV: case YACA_KEY_TYPE_EC_PUB: - ret = YACA_ERROR_NOT_IMPLEMENTED; - goto free_bio; - + //TODO NOT_IMPLEMENTED default: ret = YACA_ERROR_INVALID_ARGUMENT; goto free_bio; @@ -945,7 +941,7 @@ API int yaca_key_import(yaca_key_h *key, case YACA_KEY_TYPE_DH_PRIV: case YACA_KEY_TYPE_EC_PUB: case YACA_KEY_TYPE_EC_PRIV: - return YACA_ERROR_NOT_IMPLEMENTED; + //TODO NOT_IMPLEMENTED default: return YACA_ERROR_INVALID_ARGUMENT; } @@ -985,8 +981,9 @@ API int yaca_key_export(const yaca_key_h key, evp_key != NULL) return export_evp(evp_key, key_file_fmt, password, data, data_len); - if (key_fmt == YACA_KEY_FORMAT_PKCS8) - return YACA_ERROR_NOT_IMPLEMENTED; + if (key_fmt == YACA_KEY_FORMAT_PKCS8) { + //TODO NOT_IMPLEMENTED + } return YACA_ERROR_INVALID_ARGUMENT; } @@ -1049,7 +1046,7 @@ API int yaca_key_gen(yaca_key_h *key, case YACA_KEY_TYPE_DH_PRIV: case YACA_KEY_TYPE_EC_PRIV: - return YACA_ERROR_NOT_IMPLEMENTED; + //TODO NOT_IMPLEMENTED default: return YACA_ERROR_INVALID_ARGUMENT; } @@ -1143,7 +1140,8 @@ API int yaca_key_derive_dh(const yaca_key_h prv_key, const yaca_key_h pub_key, yaca_key_h *sym_key) { - return YACA_ERROR_NOT_IMPLEMENTED; + //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; } API int yaca_key_derive_kea(const yaca_key_h prv_key, @@ -1152,7 +1150,8 @@ API int yaca_key_derive_kea(const yaca_key_h prv_key, const yaca_key_h pub_key_auth, yaca_key_h *sym_key) { - return YACA_ERROR_NOT_IMPLEMENTED; + //TODO NOT_IMPLEMENTED + return YACA_ERROR_INVALID_ARGUMENT; } API int yaca_key_derive_pbkdf2(const char *password, diff --git a/src/sign.c b/src/sign.c index 6b76062..8ed5a6b 100644 --- a/src/sign.c +++ b/src/sign.c @@ -253,7 +253,7 @@ API int yaca_sign_init(yaca_ctx_h *ctx, case YACA_KEY_TYPE_DSA_PRIV: break; case YACA_KEY_TYPE_EC_PRIV: - return YACA_ERROR_NOT_IMPLEMENTED; + //TODO NOT_IMPLEMENTED default: return YACA_ERROR_INVALID_ARGUMENT; } @@ -508,7 +508,7 @@ API int yaca_verify_init(yaca_ctx_h *ctx, case YACA_KEY_TYPE_DSA_PUB: break; case YACA_KEY_TYPE_EC_PUB: - return YACA_ERROR_NOT_IMPLEMENTED; + //TODO NOT_IMPLEMENTED default: return YACA_ERROR_INVALID_ARGUMENT; } -- 2.7.4 From 19bfe2cbaa8eb0bb92dd30882c5c78e9513e5914 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 27 May 2016 15:37:13 +0200 Subject: [PATCH 06/16] Remove not implemented Skipjack algorithm. Change-Id: Ibc5a55bef78165344f839113361aa252749deacf --- api/yaca/yaca_types.h | 6 ------ src/encrypt.c | 4 ---- 2 files changed, 10 deletions(-) diff --git a/api/yaca/yaca_types.h b/api/yaca/yaca_types.h index 70a097d..7af84f6 100644 --- a/api/yaca/yaca_types.h +++ b/api/yaca/yaca_types.h @@ -235,12 +235,6 @@ typedef enum { * - see #yaca_block_cipher_mode_e for details on additional parameters (mandatory). */ YACA_ENC_CAST5, - - /** - * SKIPJACK algorithm. - * - Supported key length: 80 bits. - */ - YACA_ENC_UNSAFE_SKIPJACK } yaca_enc_algo_e; /** diff --git a/src/encrypt.c b/src/encrypt.c index dc1a1b3..0edeb3e 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -218,8 +218,6 @@ static const char *encrypt_algo_to_str(yaca_enc_algo_e algo) return "rc4"; case YACA_ENC_CAST5: return "cast5"; - - case YACA_ENC_UNSAFE_SKIPJACK: // TODO: add skipjack implementation default: return NULL; } @@ -291,8 +289,6 @@ int encrypt_get_algorithm(yaca_enc_algo_e algo, case YACA_ENC_UNSAFE_RC4: ret = snprintf(cipher_name, sizeof(cipher_name), "%s", algo_name); break; - case YACA_ENC_UNSAFE_SKIPJACK: - //TODO NOT_IMPLEMENTED default: return YACA_ERROR_INVALID_ARGUMENT; } -- 2.7.4 From 9d4b87bf6648013465896e58fdc9c94e37673be6 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 27 May 2016 15:47:45 +0200 Subject: [PATCH 07/16] Replace YACA_ERROR_TOO_BIG_ARGUMENT with YACA_ERROR_INVALID_ARGUMENT Change-Id: Iadf4d6a6044e6bc68389897f369064ec61ca309f --- src/encrypt.c | 2 +- src/key.c | 12 ++++++------ src/seal.c | 2 +- src/simple.c | 4 ++-- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/encrypt.c b/src/encrypt.c index 0edeb3e..385bec7 100644 --- a/src/encrypt.c +++ b/src/encrypt.c @@ -89,7 +89,7 @@ static int get_encrypt_output_length(const yaca_ctx_h ctx, size_t input_len, siz if (input_len > 0) { if ((size_t)block_size > SIZE_MAX - input_len + 1) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; *output_len = block_size + input_len - 1; } else { diff --git a/src/key.c b/src/key.c index a0e771a..3de2ba4 100755 --- a/src/key.c +++ b/src/key.c @@ -93,7 +93,7 @@ int base64_decode(const char *data, size_t data_len, BIO **output) /* This is because of BIO_new_mem_buf() having its length param typed int */ if (data_len > INT_MAX) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; /* First phase of correctness checking, calculate expected output length */ ret = base64_decode_length(data, data_len, &b64_len); @@ -204,7 +204,7 @@ int import_simple(yaca_key_h *key, } if (key_data_len > SIZE_MAX - sizeof(struct yaca_key_simple_s)) { - ret = YACA_ERROR_TOO_BIG_ARGUMENT; + ret = YACA_ERROR_INVALID_ARGUMENT; goto out; } @@ -278,7 +278,7 @@ int import_evp(yaca_key_h *key, /* This is because of BIO_new_mem_buf() having its length param typed int */ if (data_len > INT_MAX) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; src = BIO_new_mem_buf(data, data_len); if (src == NULL) { @@ -616,7 +616,7 @@ int gen_simple(struct yaca_key_simple_s **out, size_t key_bits) size_t key_byte_len = key_bits / 8; if (key_byte_len > SIZE_MAX - sizeof(struct yaca_key_simple_s)) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len); if (nk == NULL) @@ -646,7 +646,7 @@ int gen_simple_des(struct yaca_key_simple_s **out, size_t key_bits) size_t key_byte_len = key_bits / 8; if (key_byte_len > SIZE_MAX - sizeof(struct yaca_key_simple_s)) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; nk = yaca_zalloc(sizeof(struct yaca_key_simple_s) + key_byte_len); if (nk == NULL) @@ -1175,7 +1175,7 @@ API int yaca_key_derive_pbkdf2(const char *password, return YACA_ERROR_INVALID_ARGUMENT; if (key_byte_len > SIZE_MAX - sizeof(struct yaca_key_simple_s)) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; ret = digest_get_algorithm(algo, &md); if (ret != YACA_ERROR_NONE) diff --git a/src/seal.c b/src/seal.c index c17cc5d..5c1ecb1 100644 --- a/src/seal.c +++ b/src/seal.c @@ -88,7 +88,7 @@ static int get_seal_output_length(const yaca_ctx_h ctx, size_t input_len, size_t if (input_len > 0) { if ((size_t)block_size > SIZE_MAX - input_len + 1) - return YACA_ERROR_TOO_BIG_ARGUMENT; + return YACA_ERROR_INVALID_ARGUMENT; *output_len = block_size + input_len - 1; } else { diff --git a/src/simple.c b/src/simple.c index 3ba93f8..df4839a 100644 --- a/src/simple.c +++ b/src/simple.c @@ -112,7 +112,7 @@ API int yaca_encrypt(yaca_enc_algo_e algo, goto err; if (out_len > SIZE_MAX - lcipher_len) { - ret = YACA_ERROR_TOO_BIG_ARGUMENT; + ret = YACA_ERROR_INVALID_ARGUMENT; goto err; } @@ -189,7 +189,7 @@ API int yaca_decrypt(yaca_enc_algo_e algo, goto err; if (out_len > SIZE_MAX - lplain_len) { - ret = YACA_ERROR_TOO_BIG_ARGUMENT; + ret = YACA_ERROR_INVALID_ARGUMENT; goto err; } -- 2.7.4 From cae0e6ff8e9ba782d63f02921fed43e4e9955c73 Mon Sep 17 00:00:00 2001 From: Krzysztof Jackiewicz Date: Fri, 27 May 2016 15:28:34 +0200 Subject: [PATCH 08/16] Modify error codes according to ACR Change-Id: I9e41174c1a38811dd3d5d85b66513bd271cfdd0b --- api/yaca/yaca_error.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/api/yaca/yaca_error.h b/api/yaca/yaca_error.h index 5bcfec7..aca3d2d 100755 --- a/api/yaca/yaca_error.h +++ b/api/yaca/yaca_error.h @@ -47,12 +47,11 @@ extern "C" { typedef enum { YACA_ERROR_NONE = TIZEN_ERROR_NONE, YACA_ERROR_INVALID_ARGUMENT = TIZEN_ERROR_INVALID_PARAMETER, + YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, - YACA_ERROR_INTERNAL = TIZEN_ERROR_YACA | 0x02, - YACA_ERROR_TOO_BIG_ARGUMENT = TIZEN_ERROR_YACA | 0x03, - YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_YACA | 0x04, - YACA_ERROR_DATA_MISMATCH = TIZEN_ERROR_YACA | 0x05, - YACA_ERROR_PASSWORD_INVALID = TIZEN_ERROR_YACA | 0x06 + YACA_ERROR_INTERNAL = TIZEN_ERROR_YACA | 0x01, + YACA_ERROR_DATA_MISMATCH = TIZEN_ERROR_YACA | 0x02, + YACA_ERROR_PASSWORD_INVALID = TIZEN_ERROR_YACA | 0x03 } yaca_error_e; /**@}*/ -- 2.7.4 From 29c83d14715426177ea525dbb0cecca9fce07eb0 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Fri, 27 May 2016 14:34:51 +0200 Subject: [PATCH 09/16] Do not enumerate all related modules with only one @see tag. Change-Id: I5b7e3856794f099e7f2f65dde3e67bc35a81625a --- api/yaca/yaca_crypto.h | 30 ++++++++++++++++++++------ api/yaca/yaca_digest.h | 13 +++++++++--- api/yaca/yaca_encrypt.h | 28 +++++++++++++++++++------ api/yaca/yaca_key.h | 26 ++++++++++++++++++----- api/yaca/yaca_seal.h | 28 +++++++++++++++++++------ api/yaca/yaca_sign.h | 56 ++++++++++++++++++++++++++++++++++++------------- api/yaca/yaca_simple.h | 31 +++++++++++++++++++++------ 7 files changed, 165 insertions(+), 47 deletions(-) diff --git a/api/yaca/yaca_crypto.h b/api/yaca/yaca_crypto.h index 30c2734..6b8e634 100644 --- a/api/yaca/yaca_crypto.h +++ b/api/yaca/yaca_crypto.h @@ -52,6 +52,7 @@ extern "C" { * @since_tizen 3.0 * * @return YACA_ERROR_NONE on success, negative on error. + * * @see yaca_exit() */ int yaca_init(void); @@ -73,7 +74,10 @@ void yaca_exit(void); * @param[in] size Size of the allocation (bytes). * * @return NULL on failure, pointer to allocated memory otherwise. - * @see yaca_zalloc(), yaca_realloc(), yaca_free() + * + * @see yaca_zalloc() + * @see yaca_realloc() + * @see yaca_free() */ void *yaca_malloc(size_t size); @@ -85,7 +89,10 @@ void *yaca_malloc(size_t size); * @param[in] size Size of the allocation (bytes). * * @return NULL on failure, pointer to allocated and zeroed memory otherwise. - * @see yaca_malloc(), yaca_realloc(), yaca_free() + * + * @see yaca_malloc() + * @see yaca_realloc() + * @see yaca_free() */ void *yaca_zalloc(size_t size); @@ -98,7 +105,10 @@ void *yaca_zalloc(size_t size); * @param[in] size Size of the new allocation (bytes). * * @return NULL on failure, pointer to allocated memory otherwise. - * @see yaca_malloc(), yaca_zalloc(), yaca_free() + * + * @see yaca_malloc() + * @see yaca_zalloc() + * @see yaca_free() */ void *yaca_realloc(void *addr, size_t size); @@ -109,7 +119,10 @@ void *yaca_realloc(void *addr, size_t size); * @since_tizen 3.0 * * @param[in] ptr Pointer to the memory to be freed. - * @see yaca_malloc(), yaca_zalloc(), yaca_realloc() + * + * @see yaca_malloc() + * @see yaca_zalloc() + * @see yaca_realloc() * */ void yaca_free(void *ptr); @@ -138,7 +151,9 @@ int yaca_rand_bytes(char *data, size_t data_len); * @param[in] value_len Length of the parameter value. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_ex_param_e, yaca_ctx_get_param() + * + * @see #yaca_ex_param_e + * @see yaca_ctx_get_param() */ int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param, @@ -157,7 +172,9 @@ int yaca_ctx_set_param(yaca_ctx_h ctx, * @param[out] value_len Length of the parameter value will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_ex_param_e, yaca_ctx_set_param() + * + * @see #yaca_ex_param_e + * @see yaca_ctx_set_param() */ int yaca_ctx_get_param(const yaca_ctx_h ctx, yaca_ex_param_e param, @@ -171,6 +188,7 @@ int yaca_ctx_get_param(const yaca_ctx_h ctx, * @since_tizen 3.0 * * @param[in,out] ctx Crypto context. + * * @see #yaca_ctx_h * */ diff --git a/api/yaca/yaca_digest.h b/api/yaca/yaca_digest.h index 2c7be86..c91298a 100644 --- a/api/yaca/yaca_digest.h +++ b/api/yaca/yaca_digest.h @@ -48,7 +48,10 @@ extern "C" { * @param[in] algo Digest algorithm that will be used. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_digest_algo_e, yaca_digest_update(), yaca_digest_final() + * + * @see #yaca_digest_algo_e + * @see yaca_digest_update() + * @see yaca_digest_final() */ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); @@ -62,7 +65,9 @@ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); * @param[in] data_len Length of the data. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_digest_init(), yaca_digest_final() + * + * @see yaca_digest_init() + * @see yaca_digest_final() */ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); @@ -77,7 +82,9 @@ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); * @param[out] digest_len Length of the digest, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_digest_init(), yaca_digest_update() + * + * @see yaca_digest_init() + * @see yaca_digest_update() */ int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len); diff --git a/api/yaca/yaca_encrypt.h b/api/yaca/yaca_encrypt.h index cba5332..02269c0 100644 --- a/api/yaca/yaca_encrypt.h +++ b/api/yaca/yaca_encrypt.h @@ -51,7 +51,11 @@ extern "C" { * @param[in] iv Initialization vector that will be used. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_encrypt_update(), yaca_encrypt_final() + * + * @see #yaca_enc_algo_e + * @see #yaca_block_cipher_mode_e + * @see yaca_encrypt_update() + * @see yaca_encrypt_final() */ int yaca_encrypt_init(yaca_ctx_h *ctx, yaca_enc_algo_e algo, @@ -72,7 +76,9 @@ int yaca_encrypt_init(yaca_ctx_h *ctx, * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_encrypt_init(), yaca_encrypt_final() + * + * @see yaca_encrypt_init() + * @see yaca_encrypt_final() */ int yaca_encrypt_update(yaca_ctx_h ctx, const char *plain, @@ -91,7 +97,9 @@ int yaca_encrypt_update(yaca_ctx_h ctx, * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_encrypt_init(), yaca_encrypt_update() + * + * @see yaca_encrypt_init() + * @see yaca_encrypt_update() */ int yaca_encrypt_final(yaca_ctx_h ctx, char *cipher, @@ -109,7 +117,11 @@ int yaca_encrypt_final(yaca_ctx_h ctx, * @param[in] iv Initialization vector that was used to encrypt the data. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_decrypt_update(), yaca_decrypt_final() + * + * @see #yaca_enc_algo_e + * @see #yaca_block_cipher_mode_e + * @see yaca_decrypt_update() + * @see yaca_decrypt_final() */ int yaca_decrypt_init(yaca_ctx_h *ctx, yaca_enc_algo_e algo, @@ -130,7 +142,9 @@ int yaca_decrypt_init(yaca_ctx_h *ctx, * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_decrypt_init(), yaca_decrypt_final() + * + * @see yaca_decrypt_init() + * @see yaca_decrypt_final() */ int yaca_decrypt_update(yaca_ctx_h ctx, const char *cipher, @@ -149,7 +163,9 @@ int yaca_decrypt_update(yaca_ctx_h ctx, * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_decrypt_init(), yaca_decrypt_update() + * + * @see yaca_decrypt_init() + * @see yaca_decrypt_update() */ int yaca_decrypt_final(yaca_ctx_h ctx, char *plain, diff --git a/api/yaca/yaca_key.h b/api/yaca/yaca_key.h index 4786d9a..455df79 100755 --- a/api/yaca/yaca_key.h +++ b/api/yaca/yaca_key.h @@ -96,7 +96,10 @@ int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits); * * @return YACA_ERROR_NONE on success, YACA_ERROR_PASSWORD_INVALID if wrong password given, * negative on error. - * @see #yaca_key_type_e, yaca_key_export(), yaca_key_free() + * + * @see #yaca_key_type_e + * @see yaca_key_export() + * @see yaca_key_free() */ int yaca_key_import(yaca_key_h *key, yaca_key_type_e key_type, @@ -137,7 +140,11 @@ int yaca_key_import(yaca_key_h *key, * @param[out] data_len Size of the output data. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_fmt_e, #yaca_key_file_fmt_e, yaca_key_import(), yaca_key_free() + * + * @see #yaca_key_fmt_e + * @see #yaca_key_file_fmt_e + * @see yaca_key_import() + * @see yaca_key_free() */ int yaca_key_export(const yaca_key_h key, yaca_key_fmt_e key_fmt, @@ -158,7 +165,10 @@ int yaca_key_export(const yaca_key_h key, * @param[in] key_bits Length of the key (in bits) to be generated. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_key_bits_e, yaca_key_free() + * + * @see #yaca_key_type_e + * @see #yaca_key_bits_e + * @see yaca_key_free() */ int yaca_key_gen(yaca_key_h *key, yaca_key_type_e key_type, @@ -173,7 +183,10 @@ int yaca_key_gen(yaca_key_h *key, * @param[out] pub_key Extracted public key (must be freed with yaca_key_free()). * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_key_gen(), yaca_key_import(), yaca_key_free() + * + * @see yaca_key_gen() + * @see yaca_key_import() + * @see yaca_key_free() */ int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key); @@ -183,7 +196,10 @@ int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key); * @since_tizen 3.0 * * @param key Key to be freed. - * @see yaca_key_import(), yaca_key_export(), yaca_key_gen() + * + * @see yaca_key_import() + * @see yaca_key_export() + * @see yaca_key_gen() * */ void yaca_key_free(yaca_key_h key); diff --git a/api/yaca/yaca_seal.h b/api/yaca/yaca_seal.h index 81cd401..190be94 100644 --- a/api/yaca/yaca_seal.h +++ b/api/yaca/yaca_seal.h @@ -57,7 +57,11 @@ extern "C" { * @param[out] iv Generated initialization vector that will be used. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_seal_update(), yaca_seal_final() + * + * @see #yaca_enc_algo_e + * @see #yaca_block_cipher_mode_e + * @see yaca_seal_update() + * @see yaca_seal_final() */ int yaca_seal_init(yaca_ctx_h *ctx, const yaca_key_h pub_key, @@ -80,7 +84,9 @@ int yaca_seal_init(yaca_ctx_h *ctx, * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_seal_init(), yaca_seal_final() + * + * @see yaca_seal_init() + * @see yaca_seal_final() */ int yaca_seal_update(yaca_ctx_h ctx, const char *plain, @@ -99,7 +105,9 @@ int yaca_seal_update(yaca_ctx_h ctx, * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_seal_init(), yaca_seal_update() + * + * @see yaca_seal_init() + * @see yaca_seal_update() */ int yaca_seal_final(yaca_ctx_h ctx, char *cipher, @@ -119,7 +127,11 @@ int yaca_seal_final(yaca_ctx_h ctx, * @param[in] iv Initialization vector that was used for the encryption. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_open_update(), yaca_open_final() + * + * @see #yaca_enc_algo_e + * @see #yaca_block_cipher_mode_e + * @see yaca_open_update() + * @see yaca_open_final() */ int yaca_open_init(yaca_ctx_h *ctx, const yaca_key_h prv_key, @@ -142,7 +154,9 @@ int yaca_open_init(yaca_ctx_h *ctx, * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_open_init(), yaca_open_final() + * + * @see yaca_open_init() + * @see yaca_open_final() */ int yaca_open_update(yaca_ctx_h ctx, const char *cipher, @@ -161,7 +175,9 @@ int yaca_open_update(yaca_ctx_h ctx, * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_open_init(), yaca_open_update() + * + * @see yaca_open_init() + * @see yaca_open_update() */ int yaca_open_final(yaca_ctx_h ctx, char *plain, diff --git a/api/yaca/yaca_sign.h b/api/yaca/yaca_sign.h index d8098c6..0d2f399 100644 --- a/api/yaca/yaca_sign.h +++ b/api/yaca/yaca_sign.h @@ -57,9 +57,14 @@ extern "C" { * - #YACA_KEY_TYPE_EC_PRIV. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign_update(), - * yaca_sign_final(), yaca_verify_init(), yaca_verify_update(), - * yaca_verify_final() + * + * @see #yaca_key_type_e + * @see #yaca_digest_algo_e + * @see yaca_sign_update() + * @see yaca_sign_final() + * @see yaca_verify_init() + * @see yaca_verify_update() + * @see yaca_verify_final() */ int yaca_sign_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo, @@ -80,8 +85,12 @@ int yaca_sign_init(yaca_ctx_h *ctx, * - #YACA_KEY_TYPE_DES. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign_update(), - * yaca_sign_final(), yaca_memcmp() + * + * @see #yaca_key_type_e + * @see #yaca_digest_algo_e + * @see yaca_sign_update() + * @see yaca_sign_final() + * @see yaca_memcmp() */ int yaca_sign_hmac_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo, @@ -102,8 +111,12 @@ int yaca_sign_hmac_init(yaca_ctx_h *ctx, * - #YACA_KEY_TYPE_DES. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_enc_algo_e, yaca_sign_update(), - * yaca_sign_final(), yaca_memcmp() + * + * @see #yaca_key_type_e + * @see #yaca_enc_algo_e + * @see yaca_sign_update() + * @see yaca_sign_final() + * @see yaca_memcmp() */ int yaca_sign_cmac_init(yaca_ctx_h *ctx, yaca_enc_algo_e algo, @@ -120,8 +133,11 @@ int yaca_sign_cmac_init(yaca_ctx_h *ctx, * @param[in] data_len Length of the data. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_sign_init(), yaca_sign_final(), yaca_sign_hmac_init(), - * yaca_sign_cmac_init() + * + * @see yaca_sign_init() + * @see yaca_sign_final() + * @see yaca_sign_hmac_init() + * @see yaca_sign_cmac_init() */ int yaca_sign_update(yaca_ctx_h ctx, const char *data, @@ -139,8 +155,11 @@ int yaca_sign_update(yaca_ctx_h ctx, * actual number of bytes written will be returned here. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_sign_init(), yaca_sign_update(), yaca_sign_hmac_init(), - * yaca_sign_cmac_init() + * + * @see yaca_sign_init() + * @see yaca_sign_update() + * @see yaca_sign_hmac_init() + * @see yaca_sign_cmac_init() */ int yaca_sign_final(yaca_ctx_h ctx, char *signature, @@ -160,8 +179,11 @@ int yaca_sign_final(yaca_ctx_h ctx, * - #YACA_KEY_TYPE_EC_PUB. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_verify_update(), - * yaca_verify_final() + * + * @see #yaca_key_type_e + * @see #yaca_digest_algo_e + * @see yaca_verify_update() + * @see yaca_verify_final() */ int yaca_verify_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo, @@ -177,7 +199,9 @@ int yaca_verify_init(yaca_ctx_h *ctx, * @param[in] data_len Length of the data. * * @return YACA_ERROR_NONE on success, negative on error. - * @see yaca_verify_init(), yaca_verify_final() + * + * @see yaca_verify_init() + * @see yaca_verify_final() */ int yaca_verify_update(yaca_ctx_h ctx, const char *data, @@ -194,7 +218,9 @@ int yaca_verify_update(yaca_ctx_h ctx, * * @return YACA_ERROR_NONE on success, YACA_ERROR_DATA_MISMATCH if verification fails, * negative on error. - * @see yaca_verify_init(), yaca_verify_update() + * + * @see yaca_verify_init() + * @see yaca_verify_update() */ int yaca_verify_final(yaca_ctx_h ctx, const char *signature, diff --git a/api/yaca/yaca_simple.h b/api/yaca/yaca_simple.h index e50f7b2..9f3d90c 100644 --- a/api/yaca/yaca_simple.h +++ b/api/yaca/yaca_simple.h @@ -60,6 +60,7 @@ extern "C" { * @param[out] digest_len Length of message digest (depends on algorithm). * * @return YACA_ERROR_NONE on success, negative on error. + * * @see #yaca_digest_algo_e */ int yaca_digest_calc(yaca_digest_algo_e algo, @@ -84,7 +85,10 @@ int yaca_digest_calc(yaca_digest_algo_e algo, * @param[out] cipher_len Length of the encrypted data (may be larger than decrypted). * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_decrypt() + * + * @see #yaca_enc_algo_e + * @see #yaca_block_cipher_mode_e + * @see yaca_decrypt() */ int yaca_encrypt(yaca_enc_algo_e algo, yaca_block_cipher_mode_e bcm, @@ -111,7 +115,10 @@ int yaca_encrypt(yaca_enc_algo_e algo, * @param[out] plain_len Length of the decrypted data. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_enc_algo_e, #yaca_block_cipher_mode_e, yaca_encrypt() + * + * @see #yaca_enc_algo_e + * @see #yaca_block_cipher_mode_e + * @see yaca_encrypt() */ int yaca_decrypt(yaca_enc_algo_e algo, yaca_block_cipher_mode_e bcm, @@ -140,7 +147,10 @@ int yaca_decrypt(yaca_enc_algo_e algo, * @param[out] signature_len Length of the signature. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_verify(), + * + * @see #yaca_key_type_e + * @see #yaca_digest_algo_e + * @see yaca_verify() */ int yaca_sign(yaca_digest_algo_e algo, const yaca_key_h key, @@ -167,7 +177,10 @@ int yaca_sign(yaca_digest_algo_e algo, * * @return YACA_ERROR_NONE on success, YACA_ERROR_SIGNATURE_INVALID if verification fails, * negative on error. - * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_sign(), + * + * @see #yaca_key_type_e + * @see #yaca_digest_algo_e + * @see yaca_sign() */ int yaca_verify(yaca_digest_algo_e algo, const yaca_key_h key, @@ -195,7 +208,10 @@ int yaca_verify(yaca_digest_algo_e algo, * @param[out] mac_len Length of the MAC. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_digest_algo_e, yaca_memcmp() + * + * @see #yaca_key_type_e + * @see #yaca_digest_algo_e + * @see yaca_memcmp() */ int yaca_hmac(yaca_digest_algo_e algo, const yaca_key_h key, @@ -223,7 +239,10 @@ int yaca_hmac(yaca_digest_algo_e algo, * @param[out] mac_len Length of the MAC. * * @return YACA_ERROR_NONE on success, negative on error. - * @see #yaca_key_type_e, #yaca_enc_algo_e, yaca_memcmp() + * + * @see #yaca_key_type_e + * @see #yaca_enc_algo_e + * @see yaca_memcmp() */ int yaca_cmac(yaca_enc_algo_e algo, const yaca_key_h key, -- 2.7.4 From 0e25baf4e38d99bd52336c6b562ff9bcf9d415e4 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 30 May 2016 12:16:17 +0200 Subject: [PATCH 10/16] ACR: yaca_seal.h doxygen fixes Change-Id: Ia0956240a40fb5a4ac39a1cdee1aeaa93699c578 --- api/yaca/yaca_seal.h | 121 ++++++++++++++++++++++++++++++++------------------- 1 file changed, 77 insertions(+), 44 deletions(-) diff --git a/api/yaca/yaca_seal.h b/api/yaca/yaca_seal.h index 190be94..40a6f24 100644 --- a/api/yaca/yaca_seal.h +++ b/api/yaca/yaca_seal.h @@ -17,7 +17,7 @@ */ /** - * @file seal.h + * @file yaca_seal.h * @brief */ @@ -48,15 +48,21 @@ extern "C" { * * @since_tizen 3.0 * - * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()). - * @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. - * @param[out] iv Generated initialization vector that will be used. - * - * @return YACA_ERROR_NONE on success, negative on error. + * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()) + * @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 + * @param[out] iv Generated initialization vector that will be used + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect algo, bcm, sym_key_bits, invalid prv_key) + * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error + * @retval #YACA_ERROR_INTERNAL Internal error * * @see #yaca_enc_algo_e * @see #yaca_block_cipher_mode_e @@ -76,14 +82,19 @@ int yaca_seal_init(yaca_ctx_h *ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx Context created by yaca_seal_init(). - * @param[in] plain Plain text to be encrypted. - * @param[in] plain_len Length of the plain text. - * @param[out] cipher Buffer for the encrypted data (must be allocated by client, see - * yaca_get_output_length()). - * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. + * @param[in,out] ctx Context created by yaca_seal_init() + * @param[in] plain Plain text to be encrypted + * @param[in] plain_len Length of the plain text + * @param[out] cipher Buffer for the encrypted data + * (must be allocated by client, see yaca_get_output_length()) + * @param[out] cipher_len Length of the encrypted data, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_seal_init() * @see yaca_seal_final() @@ -99,12 +110,17 @@ int yaca_seal_update(yaca_ctx_h ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx A valid seal context. - * @param[out] cipher Final piece of the encrypted data (must be allocated by client, see - * yaca_get_block_length()). - * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. + * @param[in,out] ctx A valid seal context + * @param[out] cipher Final piece of the encrypted data + * (must be allocated by client, see yaca_get_block_length()) + * @param[out] cipher_len Length of the final piece, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_seal_init() * @see yaca_seal_update() @@ -118,15 +134,22 @@ int yaca_seal_final(yaca_ctx_h ctx, * * @since_tizen 3.0 * - * @param[out] ctx Newly created context. Must be freed by yaca_ctx_free(). - * @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. - * @param[in] sym_key_bits Symmetric key length (in bits) that was used for the encryption. - * @param[in] sym_key Symmetric key, encrypted with the public key, that was used to encrypt the data. - * @param[in] iv Initialization vector that was used for the encryption. - * - * @return YACA_ERROR_NONE on success, negative on error. + * @param[out] ctx Newly created context (must be freed by yaca_ctx_free()) + * @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 + * @param[in] sym_key_bits Symmetric key length (in bits) that was used for the encryption + * @param[in] sym_key Symmetric key, encrypted with the public key, + * that was used to encrypt the data + * @param[in] iv Initialization vector that was used for the encryption + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect algo, bcm, sym_key_bits, + * invalid 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_block_cipher_mode_e @@ -146,14 +169,19 @@ int yaca_open_init(yaca_ctx_h *ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx Context created by yaca_open_init(). - * @param[in] cipher Cipher text to be decrypted. - * @param[in] cipher_len Length of the cipher text. - * @param[out] plain Buffer for the decrypted data (must be allocated by client, see - * yaca_get_output_length()). - * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. + * @param[in,out] ctx Context created by yaca_open_init() + * @param[in] cipher Cipher text to be decrypted + * @param[in] cipher_len Length of the cipher text + * @param[out] plain Buffer for the decrypted data + * (must be allocated by client, see yaca_get_output_length()) + * @param[out] plain_len Length of the decrypted data, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_open_init() * @see yaca_open_final() @@ -169,12 +197,17 @@ int yaca_open_update(yaca_ctx_h ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx A valid open context. - * @param[out] plain Final piece of the decrypted data (must be allocated by client, see - * yaca_get_block_length()). - * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. - * - * @return YACA_ERROR_NONE on success, negative on error. + * @param[in,out] ctx A valid open context + * @param[out] plain Final piece of the decrypted data + * (must be allocated by client, see yaca_get_block_length()) + * @param[out] plain_len Length of the final piece, + * actual number of bytes written will be returned here + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_open_init() * @see yaca_open_update() -- 2.7.4 From a9b8123fb4c8653801a8b0794be91f1335f585c9 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 30 May 2016 12:53:53 +0200 Subject: [PATCH 11/16] ACR: yaca_encrypt.h doxygen fixes Change-Id: Id2603e9f858894eafc19e850909685d9801a5081 --- api/yaca/yaca_encrypt.h | 119 +++++++++++++++++++++++++++++++----------------- 1 file changed, 77 insertions(+), 42 deletions(-) diff --git a/api/yaca/yaca_encrypt.h b/api/yaca/yaca_encrypt.h index 02269c0..23ed8ba 100644 --- a/api/yaca/yaca_encrypt.h +++ b/api/yaca/yaca_encrypt.h @@ -17,7 +17,7 @@ */ /** - * @file encrypt.h + * @file yaca_encrypt.h * @brief */ @@ -44,13 +44,18 @@ extern "C" { * * @since_tizen 3.0 * - * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()). - * @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. - * @param[in] iv Initialization vector that will be used. + * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()) + * @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 + * @param[in] iv Initialization vector that will be used * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect algo, bcm, invalid 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_block_cipher_mode_e @@ -68,14 +73,19 @@ int yaca_encrypt_init(yaca_ctx_h *ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx Context created by yaca_encrypt_init(). - * @param[in] plain Plain text to be encrypted. - * @param[in] plain_len Length of the plain text. - * @param[out] cipher Buffer for the encrypted data (must be allocated by client, see - * yaca_get_output_length()). - * @param[out] cipher_len Length of the encrypted data, actual number of bytes written will be returned here. + * @param[in,out] ctx Context created by yaca_encrypt_init() + * @param[in] plain Plain text to be encrypted + * @param[in] plain_len Length of the plain text + * @param[out] cipher Buffer for the encrypted data + * (must be allocated by client, see yaca_get_output_length()) + * @param[out] cipher_len Length of the encrypted data, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_encrypt_init() * @see yaca_encrypt_final() @@ -91,12 +101,17 @@ int yaca_encrypt_update(yaca_ctx_h ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx A valid encrypt context. - * @param[out] cipher Final piece of the encrypted data (must be allocated by client, see - * yaca_get_block_length()). - * @param[out] cipher_len Length of the final piece, actual number of bytes written will be returned here. + * @param[in,out] ctx A valid encrypt context + * @param[out] cipher Final piece of the encrypted data + * (must be allocated by client, see yaca_get_block_length()) + * @param[out] cipher_len Length of the final piece, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_encrypt_init() * @see yaca_encrypt_update() @@ -110,13 +125,18 @@ int yaca_encrypt_final(yaca_ctx_h ctx, * * @since_tizen 3.0 * - * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()). - * @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. - * @param[in] iv Initialization vector that was used to encrypt the data. + * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()) + * @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 + * @param[in] iv Initialization vector that was used to encrypt the data * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect algo, bcm, invalid 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_block_cipher_mode_e @@ -134,14 +154,19 @@ int yaca_decrypt_init(yaca_ctx_h *ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx Context created by yaca_decrypt_init(). - * @param[in] cipher Cipher text to be decrypted. - * @param[in] cipher_len Length of the cipher text. - * @param[out] plain Buffer for the decrypted data (must be allocated by client, see - * yaca_get_output_length()). - * @param[out] plain_len Length of the decrypted data, actual number of bytes written will be returned here. + * @param[in,out] ctx Context created by yaca_decrypt_init() + * @param[in] cipher Cipher text to be decrypted + * @param[in] cipher_len Length of the cipher text + * @param[out] plain Buffer for the decrypted data + * (must be allocated by client, see yaca_get_output_length()) + * @param[out] plain_len Length of the decrypted data, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_decrypt_init() * @see yaca_decrypt_final() @@ -157,12 +182,17 @@ int yaca_decrypt_update(yaca_ctx_h ctx, * * @since_tizen 3.0 * - * @param[in,out] ctx A valid decrypt context. - * @param[out] plain Final piece of the decrypted data (must be allocated by client, see - * yaca_get_block_length()). - * @param[out] plain_len Length of the final piece, actual number of bytes written will be returned here. + * @param[in,out] ctx A valid decrypt context + * @param[out] plain Final piece of the decrypted data + * (must be allocated by client, see yaca_get_block_length()) + * @param[out] plain_len Length of the final piece, + * actual number of bytes written will be returned here * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_decrypt_init() * @see yaca_decrypt_update() @@ -179,12 +209,17 @@ int yaca_decrypt_final(yaca_ctx_h ctx, * @remarks If returned iv_bits equals 0 that means that for this * specific algorithm and its parameters IV is not used. * - * @param[in] algo Encryption algorithm. - * @param[in] bcm Chain mode. - * @param[in] key_bits Key length in bits. - * @param[out] iv_bits Recommended IV length in bits. + * @param[in] algo Encryption algorithm + * @param[in] bcm Chain mode + * @param[in] key_bits Key length in bits + * @param[out] iv_bits Recommended IV length in bits + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * invalid algo, bcm or key_bits) + * @retval #YACA_ERROR_INTERNAL Internal error * - * @return YACA_ERROR_NONE on success, negative on error. */ int yaca_get_iv_bits(yaca_enc_algo_e algo, yaca_block_cipher_mode_e bcm, -- 2.7.4 From 03d82d98a4268246cd9a552cffd79aea265fce64 Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 30 May 2016 13:27:44 +0200 Subject: [PATCH 12/16] ACR: yaca_digest.h doxygen fixes Change-Id: Ia6f8d263b7c31b22fe7d97c4bedd3754b3ae00dc --- api/yaca/yaca_digest.h | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/api/yaca/yaca_digest.h b/api/yaca/yaca_digest.h index c91298a..72d6fe1 100644 --- a/api/yaca/yaca_digest.h +++ b/api/yaca/yaca_digest.h @@ -17,7 +17,7 @@ */ /** - * @file digest.h + * @file yaca_digest.h * @brief */ @@ -44,10 +44,15 @@ extern "C" { * * @since_tizen 3.0 * - * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()). - * @param[in] algo Digest algorithm that will be used. + * @param[out] ctx Newly created context (must be freed with yaca_ctx_free()) + * @param[in] algo Digest algorithm that will be used * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect 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_update() @@ -60,11 +65,15 @@ int yaca_digest_init(yaca_ctx_h *ctx, yaca_digest_algo_e algo); * * @since_tizen 3.0 * - * @param[in,out] ctx Context created by yaca_digest_init(). - * @param[in] data Data from which the digest is to be calculated. - * @param[in] data_len Length of the data. + * @param[in,out] ctx Context created by yaca_digest_init() + * @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. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_digest_init() * @see yaca_digest_final() @@ -76,12 +85,17 @@ int yaca_digest_update(yaca_ctx_h ctx, const char *data, size_t data_len); * * @since_tizen 3.0 * - * @param[in,out] ctx A valid digest context. - * @param[out] digest Buffer for the message digest (must be allocated by client, - * see yaca_get_digest_length()). - * @param[out] digest_len Length of the digest, actual number of bytes written will be returned here. - * - * @return YACA_ERROR_NONE on success, negative on error. + * @param[in,out] ctx A valid digest context + * @param[out] digest Buffer for the message digest + * (must be allocated by client, see yaca_get_digest_length()) + * @param[out] digest_len Length of the digest, + * actual number of bytes written will be returned here + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_digest_init() * @see yaca_digest_update() -- 2.7.4 From 774dc5ac8446f75fc7afbf3b0549854bc109b3af Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 30 May 2016 14:32:44 +0200 Subject: [PATCH 13/16] ACR: yaca_crypto.h doxygen fixes Change-Id: I421e3095f70efe3264461fbd364d813eb999d93e --- api/yaca/yaca_crypto.h | 88 +++++++++++++++++++++++++++++++------------------- 1 file changed, 54 insertions(+), 34 deletions(-) diff --git a/api/yaca/yaca_crypto.h b/api/yaca/yaca_crypto.h index 6b8e634..3672972 100644 --- a/api/yaca/yaca_crypto.h +++ b/api/yaca/yaca_crypto.h @@ -17,7 +17,7 @@ */ /** - * @file crypto.h + * @file yaca_crypto.h * @brief */ @@ -51,7 +51,10 @@ extern "C" { * * @since_tizen 3.0 * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error + * @retval #YACA_ERROR_INTERNAL Internal error * * @see yaca_exit() */ @@ -71,9 +74,9 @@ void yaca_exit(void); * * @since_tizen 3.0 * - * @param[in] size Size of the allocation (bytes). + * @param[in] size Size of the allocation (bytes) * - * @return NULL on failure, pointer to allocated memory otherwise. + * @return NULL on failure, pointer to allocated memory otherwise * * @see yaca_zalloc() * @see yaca_realloc() @@ -86,9 +89,9 @@ void *yaca_malloc(size_t size); * * @since_tizen 3.0 * - * @param[in] size Size of the allocation (bytes). + * @param[in] size Size of the allocation (bytes) * - * @return NULL on failure, pointer to allocated and zeroed memory otherwise. + * @return NULL on failure, pointer to allocated and zeroed memory otherwise * * @see yaca_malloc() * @see yaca_realloc() @@ -101,10 +104,10 @@ void *yaca_zalloc(size_t size); * * @since_tizen 3.0 * - * @param[in] addr Address of the memory to be reallocated. - * @param[in] size Size of the new allocation (bytes). + * @param[in] addr Address of the memory to be reallocated + * @param[in] size Size of the new allocation (bytes) * - * @return NULL on failure, pointer to allocated memory otherwise. + * @return NULL on failure, pointer to allocated memory otherwise * * @see yaca_malloc() * @see yaca_zalloc() @@ -118,12 +121,11 @@ void *yaca_realloc(void *addr, size_t size); * * @since_tizen 3.0 * - * @param[in] ptr Pointer to the memory to be freed. + * @param[in] ptr Pointer to the memory to be freed * * @see yaca_malloc() * @see yaca_zalloc() * @see yaca_realloc() - * */ void yaca_free(void *ptr); @@ -132,10 +134,13 @@ void yaca_free(void *ptr); * * @since_tizen 3.0 * - * @param[in,out] data Pointer to the memory to be randomized. - * @param[in] data_len Length of the memory to be randomized. + * @param[in,out] data Pointer to the memory to be randomized + * @param[in] data_len Length of the memory to be randomized * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0) + * @retval #YACA_ERROR_INTERNAL Internal error */ int yaca_rand_bytes(char *data, size_t data_len); @@ -145,12 +150,16 @@ int yaca_rand_bytes(char *data, size_t data_len); * * @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,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 * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect context, invalid param) + * @retval #YACA_ERROR_INTERNAL Internal error * * @see #yaca_ex_param_e * @see yaca_ctx_get_param() @@ -166,12 +175,17 @@ int yaca_ctx_set_param(yaca_ctx_h ctx, * * @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] 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 * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context, invalid 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() @@ -183,11 +197,11 @@ int yaca_ctx_get_param(const yaca_ctx_h ctx, /** * @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_CTX_NULL is allowed. * * @since_tizen 3.0 * - * @param[in,out] ctx Crypto context. + * @param[in,out] ctx Crypto context * * @see #yaca_ctx_h * @@ -200,11 +214,15 @@ void yaca_ctx_free(yaca_ctx_h ctx); * * @since_tizen 3.0 * - * @param[in] ctx Previously initialized crypto context. - * @param[in] input_len Length of the input data to be processed. - * @param[in] output_len Required length of the output. + * @param[in] ctx Previously initialized crypto context + * @param[in] input_len Length of the input data to be processed + * @param[out] output_len Required length of the output * - * @return negative on error or length of output. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, + * incorrect context, invalid 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); @@ -234,11 +252,13 @@ int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len, size_t *outpu * * @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. + * @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 + * @return #YACA_ERROR_NONE when buffers are equal otherwise #YACA_ERROR_DATA_MISMATCH + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_DATA_MISMATCH Buffers are different */ int yaca_memcmp(const void *first, const void *second, size_t len); -- 2.7.4 From 0559d632bcd7a31c4410f3568e7a93b7deeeaeec Mon Sep 17 00:00:00 2001 From: Dariusz Michaluk Date: Mon, 30 May 2016 15:16:38 +0200 Subject: [PATCH 14/16] ACR: yaca_error.h doxygen fixes Change-Id: I2555c31e6890d2d184c2bc1e454f18271f26db6b --- api/yaca/yaca_error.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/api/yaca/yaca_error.h b/api/yaca/yaca_error.h index aca3d2d..edbbfe7 100755 --- a/api/yaca/yaca_error.h +++ b/api/yaca/yaca_error.h @@ -17,7 +17,7 @@ */ /** - * @file error.h + * @file yaca_error.h * @brief */ @@ -45,12 +45,18 @@ extern "C" { * @since_tizen 3.0 */ typedef enum { + /** Successful */ YACA_ERROR_NONE = TIZEN_ERROR_NONE, + /** Invalid function parameter */ YACA_ERROR_INVALID_ARGUMENT = TIZEN_ERROR_INVALID_PARAMETER, + /** Out of memory */ YACA_ERROR_OUT_OF_MEMORY = TIZEN_ERROR_OUT_OF_MEMORY, + /** Internal error */ YACA_ERROR_INTERNAL = TIZEN_ERROR_YACA | 0x01, + /** Data mismatch */ YACA_ERROR_DATA_MISMATCH = TIZEN_ERROR_YACA | 0x02, + /** Invalid password */ YACA_ERROR_PASSWORD_INVALID = TIZEN_ERROR_YACA | 0x03 } yaca_error_e; -- 2.7.4 From ae7a3cd315b976ba4e8a46566b711adbb46c50ce Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Fri, 27 May 2016 14:07:02 +0200 Subject: [PATCH 15/16] ACR: remove key derive dh/kea Change-Id: I0008dd2179597bb54e4ca3e8da8a0bb862d4fce9 --- api/yaca/yaca_key.h | 34 ---------------------------------- examples/CMakeLists.txt | 1 - src/key.c | 18 ------------------ 3 files changed, 53 deletions(-) diff --git a/api/yaca/yaca_key.h b/api/yaca/yaca_key.h index 455df79..0a3cc42 100755 --- a/api/yaca/yaca_key.h +++ b/api/yaca/yaca_key.h @@ -215,40 +215,6 @@ void yaca_key_free(yaca_key_h key); */ /** - * @brief Derives a key using Diffie-Helmann or EC Diffie-Helmann key exchange protocol. - * - * @param[in] prv_key Our private key. - * @param[in] pub_key Peer public key. - * @param[out] sym_key Shared secret, that can be used as a symmetric key - * (must be freed with yaca_key_free()). - * - * @return YACA_ERROR_NONE on success, negative on error. - */ -int yaca_key_derive_dh(const yaca_key_h prv_key, - const yaca_key_h pub_key, - yaca_key_h *sym_key); - -/** - * @brief Derives a key using KEA key exchange protocol. - * - * @param[in] prv_key Our DH private component. - * @param[in] pub_key Peers' DH public component. - * @param[in] prv_key_auth Our private key used to create signature on our - * DH public component sent to peer to verify our identity. - * @param[in] pub_key_auth Peers' public key used for signature verification - * of pub_key from peer (peer authentication). - * @param[out] sym_key Shared secret, that can be used as a symmetric key - * (must be freed with yaca_key_free()). - * - * @return YACA_ERROR_NONE on success, negative on error. - */ -int yaca_key_derive_kea(const yaca_key_h prv_key, - const yaca_key_h pub_key, - const yaca_key_h prv_key_auth, - const yaca_key_h pub_key_auth, - yaca_key_h *sym_key); - -/** * @brief Derives a key from user password (PKCS #5 a.k.a. pbkdf2 algorithm). * * @since_tizen 3.0 diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index af00c1c..c1f6ef1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -48,7 +48,6 @@ BUILD_EXAMPLE("yaca-example-encrypt" encrypt.c) BUILD_EXAMPLE("yaca-example-seal" seal.c) BUILD_EXAMPLE("yaca-example-encrypt-gcm-ccm" encrypt_aes_gcm_ccm.c) BUILD_EXAMPLE("yaca-example-sign" sign.c) -BUILD_EXAMPLE("yaca-example-key-exchange" key_exchange.c) BUILD_EXAMPLE("yaca-example-key-impexp" key_import_export.c) BUILD_EXAMPLE("yaca-example-key-password" key_password.c) diff --git a/src/key.c b/src/key.c index 3de2ba4..cdffd45 100755 --- a/src/key.c +++ b/src/key.c @@ -1136,24 +1136,6 @@ API void yaca_key_free(yaca_key_h key) } } -API int yaca_key_derive_dh(const yaca_key_h prv_key, - const yaca_key_h pub_key, - yaca_key_h *sym_key) -{ - //TODO NOT_IMPLEMENTED - return YACA_ERROR_INVALID_ARGUMENT; -} - -API int yaca_key_derive_kea(const yaca_key_h prv_key, - const yaca_key_h pub_key, - const yaca_key_h prv_key_auth, - const yaca_key_h pub_key_auth, - yaca_key_h *sym_key) -{ - //TODO NOT_IMPLEMENTED - return YACA_ERROR_INVALID_ARGUMENT; -} - API int yaca_key_derive_pbkdf2(const char *password, const char *salt, size_t salt_len, -- 2.7.4 From 2c6b2974d28f6227f26ed744f252bf543961ec9b Mon Sep 17 00:00:00 2001 From: Lukasz Pawelczyk Date: Fri, 27 May 2016 16:08:33 +0200 Subject: [PATCH 16/16] ACR: yaca_key.h doxygen fixes @return statements cleaned up Added @retval statements Removed dot at the end of some statements Change-Id: If0495e03f6bf0fc24341f217c94dbbf68550a72e --- api/yaca/yaca_key.h | 119 +++++++++++++++++++++++++++++++--------------------- todo.txt | 3 ++ 2 files changed, 74 insertions(+), 48 deletions(-) diff --git a/api/yaca/yaca_key.h b/api/yaca/yaca_key.h index 0a3cc42..bd959b2 100755 --- a/api/yaca/yaca_key.h +++ b/api/yaca/yaca_key.h @@ -17,7 +17,7 @@ */ /** - * @file key.h + * @file yaca_key.h * @brief */ @@ -41,17 +41,17 @@ extern "C" { #define YACA_KEY_NULL ((yaca_key_h) NULL) -// TODO: We need a way to import keys encrypted with hw (or other) keys. New function like yaca_key_load or sth?? - /** * @brief Get key's type. * * @since_tizen 3.0 * - * @param[in] key Key which type we return. - * @param[out] key_type Key type. + * @param[in] key Key which type we return + * @param[out] key_type Key type * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Either of the params is NULL */ int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type); @@ -60,10 +60,13 @@ int yaca_key_get_type(const yaca_key_h key, yaca_key_type_e *key_type); * * @since_tizen 3.0 * - * @param[in] key Key which length we return. - * @param[out] key_bits Key length in bits. + * @param[in] key Key which length we return + * @param[out] key_bits Key length in bits * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT 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); @@ -86,16 +89,22 @@ int yaca_key_get_bits(const yaca_key_h key, size_t *key_bits); * * 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. - * - * @param[out] key Returned key (must be freed with yaca_key_free()). - * @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. - * - * @return YACA_ERROR_NONE on success, YACA_ERROR_PASSWORD_INVALID if wrong password given, - * negative on error. + * password and check for the #YACA_ERROR_PASSWORD_INVALID return code. + * + * @param[out] key Returned key (must be freed with yaca_key_free()) + * @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 + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect 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 + * and none was given * * @see #yaca_key_type_e * @see yaca_key_export() @@ -131,15 +140,20 @@ int yaca_key_import(yaca_key_h *key, * TODO:document the default encryption algorithm (AES256 for FORMAT_DEFAULT, * unknown yet for the FORMAT_PKCS8). * - * @param[in] key Key to be exported. - * @param[in] key_fmt Format of the key. - * @param[in] key_file_fmt Format of the key file. - * @param[in] password Password used for the encryption (can be NULL). + * @param[in] key Key to be exported + * @param[in] key_fmt Format of the key + * @param[in] key_file_fmt Format of the key file + * @param[in] password Password used for the encryption (can be NULL) * @param[out] data Data, allocated by the library, containing exported key - * (must be freed with yaca_free()). - * @param[out] data_len Size of the output data. + * (must be freed with yaca_free()) + * @param[out] data_len Size of the output data * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect key formats 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 @@ -160,11 +174,16 @@ int yaca_key_export(const yaca_key_h key, * * @remarks This function is used to generate symmetric and private asymmetric keys. * - * @param[out] key Newly generated key (must be freed with yaca_key_free()). - * @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[in] key_type Type of the key to be generated + * @param[in] key_bits Length of the key (in bits) to be generated * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT 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 @@ -179,10 +198,14 @@ int yaca_key_gen(yaca_key_h *key, * * @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[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()) * - * @return YACA_ERROR_NONE on success, negative on error. + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT prv_key is of incorrect 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_import() @@ -195,12 +218,11 @@ int yaca_key_extract_public(const yaca_key_h prv_key, yaca_key_h *pub_key); * * @since_tizen 3.0 * - * @param key Key to be freed. + * @param[in,out] key Key to be freed * * @see yaca_key_import() * @see yaca_key_export() * @see yaca_key_gen() - * */ void yaca_key_free(yaca_key_h key); @@ -219,15 +241,20 @@ void yaca_key_free(yaca_key_h key); * * @since_tizen 3.0 * - * @param[in] password User password as a NULL-terminated string. - * @param[in] salt Salt, should be non-zero. - * @param[in] salt_len Length of the salt. - * @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()). - * - * @return YACA_ERROR_NONE on success, negative on error. + * @param[in] password User password as a NULL-terminated string + * @param[in] salt Salt, should be non-zero + * @param[in] salt_len Length of the salt + * @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()) + * + * @return #YACA_ERROR_NONE on success, negative on error + * @retval #YACA_ERROR_NONE Succesful + * @retval #YACA_ERROR_INVALID_ARGUMENT Required parameters have bogus values (NULL, 0, + * incorrect algo or key_bits not dividable by 8) + * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error + * @retval #YACA_ERROR_INTERNAL Internal error */ int yaca_key_derive_pbkdf2(const char *password, const char *salt, @@ -237,10 +264,6 @@ int yaca_key_derive_pbkdf2(const char *password, size_t key_bits, yaca_key_h *key); -// TODO: specify -//int yaca_key_wrap(yaca_key_h key, ??); -//int yaca_key_unwrap(yaca_key_h key, ??); - /**@}*/ #ifdef __cplusplus diff --git a/todo.txt b/todo.txt index 216c413..26e6208 100644 --- a/todo.txt +++ b/todo.txt @@ -4,3 +4,6 @@ Global: - Importing/exporting encrypted (passphrased) RSA keys - Support for OCB mode was added in OpenSSL 1.1.0 - Remove debug function from examples +- yaca_key_wrap(), yaca_key_unwrap() +- We need a way to import keys encrypted with hw (or other) keys. New + function like yaca_key_load or sth? -- 2.7.4