* @see yaca_context_get_property()
*/
int yaca_context_set_property(yaca_context_h ctx,
- yaca_property_e property,
- const void *value,
- size_t value_len);
+ yaca_property_e property,
+ const void *value,
+ size_t value_len);
/**
* @brief Returns the non-standard context properties. Can only be called on an
* @see yaca_free()
*/
int yaca_context_get_property(const yaca_context_h ctx,
- yaca_property_e property,
- void **value,
- size_t *value_len);
+ yaca_property_e property,
+ void **value,
+ size_t *value_len);
/**
* @brief Returns the minimum required size of the output buffer for a single crypto function call.
* @retval #YACA_ERROR_INTERNAL Internal error
*/
int yaca_context_get_output_length(const yaca_context_h ctx,
- size_t input_len,
- size_t *output_len);
+ size_t input_len,
+ size_t *output_len);
/**
* @brief Destroys the crypto context. Must be called on all contexts that are
*
*/
int yaca_encrypt_get_iv_bit_length(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bit_len,
- size_t *iv_bit_len);
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bit_len,
+ size_t *iv_bit_len);
/**
* @brief Initializes an encryption context.
* @see yaca_context_destroy()
*/
int yaca_encrypt_initialize(yaca_context_h *ctx,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv);
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
* @brief Encrypts chunk of the data.
* @see yaca_context_get_output_length()
*/
int yaca_encrypt_update(yaca_context_h ctx,
- const char *plaintext,
- size_t plaintext_len,
- char *ciphertext,
- size_t *ciphertext_len);
+ const char *plaintext,
+ size_t plaintext_len,
+ char *ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Encrypts the final chunk of the data.
* @see yaca_context_get_output_length()
*/
int yaca_encrypt_finalize(yaca_context_h ctx,
- char *ciphertext,
- size_t *ciphertext_len);
+ char *ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Initializes an decryption context.
* @see yaca_context_destroy()
*/
int yaca_decrypt_initialize(yaca_context_h *ctx,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv);
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
* @brief Decrypts chunk of the data.
* @see yaca_context_get_output_length()
*/
int yaca_decrypt_update(yaca_context_h ctx,
- const char *ciphertext,
- size_t ciphertext_len,
- char *plaintext,
- size_t *plaintext_len);
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char *plaintext,
+ size_t *plaintext_len);
/**
* @brief Decrypts the final chunk of the data.
* @see yaca_context_get_output_length()
*/
int yaca_decrypt_finalize(yaca_context_h ctx,
- char *plaintext,
- size_t *plaintext_len);
+ char *plaintext,
+ size_t *plaintext_len);
/**
* @}
* @see yaca_key_destroy()
*/
int yaca_key_import(yaca_key_type_e key_type,
- const char *password,
- const char *data,
- size_t data_len,
- yaca_key_h *key);
+ const char *password,
+ const char *data,
+ size_t data_len,
+ yaca_key_h *key);
/**
* @brief Exports a key or key generation parameters to arbitrary format.
* @see yaca_key_destroy()
*/
int yaca_key_export(const yaca_key_h key,
- yaca_key_format_e key_fmt,
- yaca_key_file_format_e key_file_fmt,
- const char *password,
- char **data,
- size_t *data_len);
+ yaca_key_format_e key_fmt,
+ yaca_key_file_format_e key_file_fmt,
+ const char *password,
+ char **data,
+ size_t *data_len);
/**
* @brief Generates a secure key or key generation parameters (or an Initialization Vector).
* @see yaca_key_destroy()
*/
int yaca_key_generate(yaca_key_type_e key_type,
- size_t key_bit_len,
- yaca_key_h *key);
+ size_t key_bit_len,
+ yaca_key_h *key);
/**
* @brief Generates a secure private asymmetric key from parameters.
* @see yaca_free()
*/
int yaca_key_derive_dh(const yaca_key_h prv_key,
- const yaca_key_h pub_key,
- char **secret,
- size_t *secret_len);
+ const yaca_key_h pub_key,
+ char **secret,
+ size_t *secret_len);
/**
* @brief Derives a key material from shared secret.
* @see yaca_free()
*/
int yaca_key_derive_kdf(yaca_kdf_e kdf,
- yaca_digest_algorithm_e algo,
- const char *secret,
- size_t secret_len,
- const char *info,
- size_t info_len,
- size_t key_material_len,
- char **key_material);
+ yaca_digest_algorithm_e algo,
+ const char *secret,
+ size_t secret_len,
+ const char *info,
+ size_t info_len,
+ size_t key_material_len,
+ char **key_material);
/**
* @brief Derives a key from user password (PKCS #5 a.k.a. pbkdf2 algorithm).
* @see yaca_key_destroy()
*/
int yaca_key_derive_pbkdf2(const char *password,
- const char *salt,
- size_t salt_len,
- size_t iterations,
- yaca_digest_algorithm_e algo,
- size_t key_bit_len,
- yaca_key_h *key);
+ const char *salt,
+ size_t salt_len,
+ size_t iterations,
+ yaca_digest_algorithm_e algo,
+ size_t key_bit_len,
+ yaca_key_h *key);
/**
* @brief Release the key created by the library. Passing YACA_KEY_NULL is allowed.
* @see yaca_free()
*/
int yaca_rsa_public_encrypt(yaca_padding_e padding,
- const yaca_key_h pub_key,
- const char *plaintext,
- size_t plaintext_len,
- char **ciphertext,
- size_t *ciphertext_len);
+ const yaca_key_h pub_key,
+ const char *plaintext,
+ size_t plaintext_len,
+ char **ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Decrypts data using a RSA private key (low-level decrypt equivalent).
* @see yaca_free()
*/
int yaca_rsa_private_decrypt(yaca_padding_e padding,
- const yaca_key_h prv_key,
- const char *ciphertext,
- size_t ciphertext_len,
- char **plaintext,
- size_t *plaintext_len);
+ const yaca_key_h prv_key,
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char **plaintext,
+ size_t *plaintext_len);
/**
* @brief Encrypts data using a RSA private key (low-level sign equivalent).
* @see yaca_free()
*/
int yaca_rsa_private_encrypt(yaca_padding_e padding,
- const yaca_key_h prv_key,
- const char *plaintext,
- size_t plaintext_len,
- char **ciphertext,
- size_t *ciphertext_len);
+ const yaca_key_h prv_key,
+ const char *plaintext,
+ size_t plaintext_len,
+ char **ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Decrypts data using a RSA public key (low-level verify equivalent).
* @see yaca_free()
*/
int yaca_rsa_public_decrypt(yaca_padding_e padding,
- const yaca_key_h pub_key,
- const char *ciphertext,
- size_t ciphertext_len,
- char **plaintext,
- size_t *plaintext_len);
+ const yaca_key_h pub_key,
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char **plaintext,
+ size_t *plaintext_len);
/**
* @}
* @see yaca_context_destroy()
*/
int yaca_seal_initialize(yaca_context_h *ctx,
- const yaca_key_h pub_key,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t sym_key_bit_len,
- yaca_key_h *sym_key,
- yaca_key_h *iv);
+ const yaca_key_h pub_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t sym_key_bit_len,
+ yaca_key_h *sym_key,
+ yaca_key_h *iv);
/**
* @brief Encrypts piece of the data.
* @see yaca_context_get_output_length()
*/
int yaca_seal_update(yaca_context_h ctx,
- const char *plaintext,
- size_t plaintext_len,
- char *ciphertext,
- size_t *ciphertext_len);
+ const char *plaintext,
+ size_t plaintext_len,
+ char *ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Encrypts the final piece of the data.
* @see yaca_context_get_output_length()
*/
int yaca_seal_finalize(yaca_context_h ctx,
- char *ciphertext,
- size_t *ciphertext_len);
+ char *ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Initializes an asymmetric decryption context.
* @see yaca_context_destroy()
*/
int yaca_open_initialize(yaca_context_h *ctx,
- const yaca_key_h prv_key,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t sym_key_bit_len,
- const yaca_key_h sym_key,
- const yaca_key_h iv);
+ const yaca_key_h prv_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t sym_key_bit_len,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv);
/**
* @brief Decrypts piece of the data.
* @see yaca_context_get_output_length()
*/
int yaca_open_update(yaca_context_h ctx,
- const char *ciphertext,
- size_t ciphertext_len,
- char *plaintext,
- size_t *plaintext_len);
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char *plaintext,
+ size_t *plaintext_len);
/**
* @brief Decrypts last chunk of sealed message.
* @see yaca_context_get_output_length()
*/
int yaca_open_finalize(yaca_context_h ctx,
- char *plaintext,
- size_t *plaintext_len);
+ char *plaintext,
+ size_t *plaintext_len);
/**
* @}
* @see yaca_context_destroy()
*/
int yaca_sign_initialize(yaca_context_h *ctx,
- yaca_digest_algorithm_e algo,
- const yaca_key_h prv_key);
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h prv_key);
/**
* @brief Initializes a signature context for HMAC.
* @see yaca_context_destroy()
*/
int yaca_sign_initialize_hmac(yaca_context_h *ctx,
- yaca_digest_algorithm_e algo,
- const yaca_key_h sym_key);
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h sym_key);
/**
* @brief Initializes a signature context for CMAC.
* @see yaca_context_destroy()
*/
int yaca_sign_initialize_cmac(yaca_context_h *ctx,
- yaca_encrypt_algorithm_e algo,
- const yaca_key_h sym_key);
+ yaca_encrypt_algorithm_e algo,
+ const yaca_key_h sym_key);
/**
* @brief Feeds the message into the digital signature or MAC algorithm.
* @see yaca_sign_initialize_cmac()
*/
int yaca_sign_update(yaca_context_h ctx,
- const char *message,
- size_t message_len);
+ const char *message,
+ size_t message_len);
/**
* @brief Calculates the final signature or MAC.
* @see yaca_context_get_output_length()
*/
int yaca_sign_finalize(yaca_context_h ctx,
- char *signature,
- size_t *signature_len);
+ char *signature,
+ size_t *signature_len);
/**
* @brief Initializes a signature verification context for asymmetric signatures.
* @see yaca_context_destroy()
*/
int yaca_verify_initialize(yaca_context_h *ctx,
- yaca_digest_algorithm_e algo,
- const yaca_key_h pub_key);
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h pub_key);
/**
* @brief Feeds the message into the digital signature verification algorithm.
* @see yaca_verify_finalize()
*/
int yaca_verify_update(yaca_context_h ctx,
- const char *message,
- size_t message_len);
+ const char *message,
+ size_t message_len);
/**
* @brief Performs the verification.
* @see yaca_sign_finalize()
*/
int yaca_verify_finalize(yaca_context_h ctx,
- const char *signature,
- size_t signature_len);
+ const char *signature,
+ size_t signature_len);
/**
* @}
* @see yaca_free()
*/
int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *plaintext,
- size_t plaintext_len,
- char **ciphertext,
- size_t *ciphertext_len);
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *plaintext,
+ size_t plaintext_len,
+ char **ciphertext,
+ size_t *ciphertext_len);
/**
* @brief Decrypts data using a symmetric cipher.
* @see yaca_free()
*/
int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *ciphertext,
- size_t ciphertext_len,
- char **plaintext,
- size_t *plaintext_len);
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char **plaintext,
+ size_t *plaintext_len);
/**
* @brief Calculates a digest of a message.
* @see yaca_free()
*/
int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
- const char *message,
- size_t message_len,
- char **digest,
- size_t *digest_len);
+ const char *message,
+ size_t message_len,
+ char **digest,
+ size_t *digest_len);
/**
* @brief Creates a signature using asymmetric private key.
* @see yaca_free()
*/
int yaca_simple_calculate_signature(yaca_digest_algorithm_e algo,
- const yaca_key_h prv_key,
- const char *message,
- size_t message_len,
- char **signature,
- size_t *signature_len);
+ const yaca_key_h prv_key,
+ const char *message,
+ size_t message_len,
+ char **signature,
+ size_t *signature_len);
/**
* @brief Verifies a signature using asymmetric public key.
* @see yaca_simple_calculate_signature()
*/
int yaca_simple_verify_signature(yaca_digest_algorithm_e algo,
- const yaca_key_h pub_key,
- const char *message,
- size_t message_len,
- const char *signature,
- size_t signature_len);
+ const yaca_key_h pub_key,
+ const char *message,
+ size_t message_len,
+ const char *signature,
+ size_t signature_len);
/**
* @brief Calculates a HMAC of given message using symmetric key.
* @see yaca_free()
*/
int yaca_simple_calculate_hmac(yaca_digest_algorithm_e algo,
- const yaca_key_h sym_key,
- const char *message,
- size_t message_len,
- char **mac,
- size_t *mac_len);
+ const yaca_key_h sym_key,
+ const char *message,
+ size_t message_len,
+ char **mac,
+ size_t *mac_len);
/**
* @brief Calculates a CMAC of given message using symmetric key.
* @see yaca_free()
*/
int yaca_simple_calculate_cmac(yaca_encrypt_algorithm_e algo,
- const yaca_key_h sym_key,
- const char *message,
- size_t message_len,
- char **mac,
- size_t *mac_len);
+ const yaca_key_h sym_key,
+ const char *message,
+ size_t message_len,
+ char **mac,
+ size_t *mac_len);
/**
* @}
Differences from Tizen rules are included as "Notes". For full description of
each rule - please refer to Tizen documentation.
-[R01] [CMT_M_C89] Style for comment is the C89 "/* … */" style.
+[R01] [CMT_M_C89] Both comment styles are allowed : C89 "/* ... */" style & C99 "//" style
Note: Temporary comments may use C99 style (TODO, FIXME etc.)
[R02] [DEC_R_INL] inline keyword should sit between storage class and type.
-[R03] [IDT_R_TAB] Use tabs. All tabs are 4 characters. Indentation use only tab (No space key).
-Note: If possible use Smart Tabs, if not - 4-character tabs + alignment spaces
+[M01] [IDT_M_TAB] Use tabs. All tabs are 4 characters. Indentation use only tab (No space key).
+Note: If necessary use 4-character tabs + alignment spaces
-[R04] [IDT_R_SCH] Switch and case should be at the same indent.
+[M02] [IDT_M_SCH] Switch and case should be at the same indent.
-[R05] [IDT_R_LBL] goto labels aren't indented, allow a single space however.
+[R03] [IDT_R_LBL] goto labels aren't indented, allow a single space however.
Note: No single space allowed
-[M01] [SPC_M_KWD] Keywords have following space rules
+[M03] [SPC_M_KWD] Keywords have following space rules
-Put a space after (most) keywords (ex: if, switch, case, for, do, while).
-Exception: Do not put a space after function like keywords, such as sizeof, typeof, alignof, __attribute__. -
-[M02] [SPC_M_OPR] Operators have following space rules
+[M04] [SPC_M_OPR] Operators have following space rules
-Put a space around(on each side of) most binary and ternary operators
-Example: = + -< > * / % | & ^ <= >= == != ? :
-Do not put a space after unary operators
-Do not put a space after cast operator
-Do not put a space around the "." and "->" structure member operators.
-[M03] [SPC_M_SEP] Seperators have following space rules
+[M05] [SPC_M_SEP] Seperators have following space rules
-Put a space after closing brace when it has anything on the line.
-Exception : comma after closing brace '},'
-Put a space after comma
-Do not put a space after the function name in function calls.
-Do not put space before open square bracket '['; and inside square bracket '[', ']'.
-[M04] [BRC_M_FTN] functions have the opening brace at the beginning of the next line.
+[M06] [BRC_M_FTN] functions have the opening brace at the beginning of the next line.
-[M05] [BRC_M_SMT] Statement brace: Open brace last on the line. The closing brace is empty on a line of its own.
+[M07] [BRC_M_SMT] Statement brace: Open brace last on the line. The closing brace is empty on a line of its own.
-Exception: Where the closing race is followed by a continuation of the same statement, else should follow close brace '}',
while should follow close brace '}'
-[M06] [BRC_M_EUS] Open braces for enum, union and struct go on the same line.
+[M08] [BRC_M_EUS] Open braces for enum, union and struct go on the same line.
-[R06] [BRC_R_SST] Do not unnecessarily use braces where a single statement will do.
+[R04] [BRC_R_SST] Do not unnecessarily use braces where a single statement will do.
-Exception: if one branch of a conditional statement is a single statement, use braces in both branches.
-[R07] [LNE_R_TWS] No trailing whitespaces at the ends of lines.
+[R05] [LNE_R_TWS] No trailing whitespaces at the ends of lines.
-[R08] [LNE_R_EOF] Check for adding lines without a newline at end of file.
-Notes: File should end with '\n' (single newline at the end of file)
+[R06] [LNE_R_EOF] Check for adding lines without a newline at end of file.
+Note: File should end with '\n' (single newline at the end of file)
-[R09] In source file, the sequence of the code organization : Copyright File comments Header files Define constant and macros Declare static (private) functions Define exported (public) functions Define static (private) functions Define protected functions.
-Notes: Static (private) function code first, then functions used by other objects in library; API (public) functions at the end
+[R07] In source file, the sequence of the code organization : Copyright, File comments, Header files, Define constant and macros, Declare static (private) functions, Define exported (public) functions, Define static (private) functions, Define protected functions.
+Note: Static (private) function code first, then functions used by other objects in library; API (public) functions at the end
******** Public API should use 'API' macro - other functions are not visible outside of library
-[M07] Separate external public header(API) and internal header(declare protected functions that are not exported but use for many files)
+[M09] Separate external public header(API) and internal header(declare protected functions that are not exported but use for many files)
-[M08] External public headers include the Doxygen style for comment. ex) Variable, Function, Struct.
+[M10] External public headers include the Doxygen style for comment. ex) Variable, Function, Struct.
-[M09] In function prototypes, include parameter names with their data types and return type.
+[M11] In function prototypes, include parameter names with their data types and return type.
-[R10] Macros with multiple statements should be enclosed in a "do -while" block.
+[R08] Macros with multiple statements should be enclosed in a "do -while" block.
-[R11] ''#' symbol for macro shall be located at the first column.
+[R09] ''#' symbol for macro shall be located at the first column.
-[R12] In macro definition, every expression and the arguments in the expressions shall be enclosed by '(' and ')' for each.
+[R10] In macro definition, every expression and the arguments in the expressions shall be enclosed by '(' and ')' for each.
-[R13] Don’t declare both a structure tag and variables or typedefs in the same declaration.
+[R11] Don’t declare both a structure tag and variables or typedefs in the same declaration.
Note: Avoid use of typedefs for structures/enums unless it's needed (for handles in API etc.)
-[R14] Each variable shall be declared in the new line.
+[R12] Each variable shall be declared in the new line.
Notes: except for counters (like i, j, k, etc.).
-[M10] No mixed-case, Use underscores('_') to separate words in a name.
+[M12] No mixed-case, Use underscores('_') to separate words in a name.
-[R15] Names of macros defining constants and labels in enums are composed of capital letters, numbers and '_' character.
+[R13] Names of macros defining constants and labels in enums are composed of capital letters, numbers and '_' character.
-[R16] Name of functions are Verb + Noun to have a good representation of features.
+[R14] Name of functions are Verb + Noun to have a good representation of features.
Note: this is rule of thumb except for Public API. Public API has prefix (<library>_<module>_fcn).
--------------------------------------------------------------------------------
3. Tizen rules that should NOT be followed
--------------------------------------------------------------------------------
-[R17] Local functions whose scope is limited to the current source file have "static" keyword and names started with "__".
-Note: static functions should not include "prefix" but can have arbitrary names (see R16).
+[R15] Local functions whose scope is limited to the current source file have "static" keyword and names started with "__".
+Note: static functions should not include "prefix" but can have arbitrary names (see R14).
-[R18] Names of protected(global) functions in internal header are started with '_' character.
-Note: Functions shared between multiple objects can have arbitrary naming (see R16)
+[R16] Names of protected(global) functions in internal header are started with '_' character.
+Note: Functions shared between multiple objects can have arbitrary naming (see R14)
/* Calculate digest */
ret = yaca_simple_calculate_digest(YACA_DIGEST_SHA256, INPUT_DATA, INPUT_DATA_SIZE,
- &digest, &digest_len);
+ &digest, &digest_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Key generation */
ret = yaca_key_derive_pbkdf2("foo bar", "123456789", 10, 1000,
- YACA_DIGEST_SHA256, YACA_KEY_LENGTH_256BIT, &key);
+ YACA_DIGEST_SHA256, YACA_KEY_LENGTH_256BIT, &key);
if (ret != YACA_ERROR_NONE)
goto exit;
/* IV generation */
ret = yaca_encrypt_get_iv_bit_length(YACA_ENCRYPT_AES, YACA_BCM_CTR, YACA_KEY_LENGTH_256BIT,
- &iv_bit_len);
+ &iv_bit_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Encryption */
{
ret = yaca_simple_encrypt(YACA_ENCRYPT_AES, YACA_BCM_CTR, key, iv,
- INPUT_DATA, INPUT_DATA_SIZE, &encrypted, &encrypted_len);
+ INPUT_DATA, INPUT_DATA_SIZE, &encrypted, &encrypted_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Decryption */
{
ret = yaca_simple_decrypt(YACA_ENCRYPT_AES, YACA_BCM_CTR, key, iv,
- encrypted, encrypted_len, &decrypted, &decrypted_len);
+ encrypted, encrypted_len, &decrypted, &decrypted_len);
if (ret != YACA_ERROR_NONE)
goto exit;
iv_material_len = YACA_KEY_LENGTH_IV_128BIT / 8;
temp_material_len = key_material_len + iv_material_len;
ret = yaca_key_derive_kdf(YACA_KDF_X942, YACA_DIGEST_SHA512, secret, secret_len,
- NULL, 0, temp_material_len, &temp_material);
+ NULL, 0, temp_material_len, &temp_material);
if (ret != YACA_ERROR_NONE)
goto exit;
/* PEM private */
ret = yaca_key_export(rsa_priv, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM, NULL,
- &pem_priv, &pem_priv_len);
+ &pem_priv, &pem_priv_len);
if (ret != YACA_ERROR_NONE)
goto exit;
pem_priv = NULL;
ret = yaca_key_export(pem_priv_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_PEM,
- NULL, &pem_priv, &pem_priv_len);
+ NULL, &pem_priv, &pem_priv_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* DER public */
ret = yaca_key_export(rsa_pub, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_DER, NULL,
- &der_pub, &der_pub_len);
+ &der_pub, &der_pub_len);
if (ret != YACA_ERROR_NONE)
goto exit;
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);
+ NULL, &der_pub, &der_pub_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* BASE64 */
ret = yaca_key_export(sym_key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_BASE64, NULL,
- &b64, &b64_len);
+ &b64, &b64_len);
if (ret != YACA_ERROR_NONE)
goto exit;
b64 = NULL;
ret = yaca_key_export(b64_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_BASE64, NULL,
- &b64, &b64_len);
+ &b64, &b64_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* RAW */
ret = yaca_key_export(sym_key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL,
- &raw, &raw_len);
+ &raw, &raw_len);
if (ret != YACA_ERROR_NONE)
goto exit;
raw = NULL;
ret = yaca_key_export(raw_imported, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL,
- &raw, &raw_len);
+ &raw, &raw_len);
if (ret != YACA_ERROR_NONE)
goto exit;
goto exit;
ret = yaca_key_export(key, YACA_KEY_FORMAT_PKCS8, YACA_KEY_FILE_FORMAT_PEM, password,
- &key_data, &key_data_len);
+ &key_data, &key_data_len);
if (ret == YACA_ERROR_INVALID_PARAMETER)
printf("invalid parameter, probably a missing password for PKCS8\n");
if (ret != YACA_ERROR_NONE)
key_data = NULL;
ret = yaca_key_export(key, YACA_KEY_FORMAT_PKCS8, YACA_KEY_FILE_FORMAT_PEM, password,
- &key_data, &key_data_len);
+ &key_data, &key_data_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* IV generation */
ret = yaca_encrypt_get_iv_bit_length(YACA_ENCRYPT_AES, YACA_BCM_WRAP, YACA_KEY_LENGTH_256BIT,
- &iv_bit_len);
+ &iv_bit_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Key wrapping */
{
ret = yaca_key_export(aes_key, YACA_KEY_FORMAT_DEFAULT, YACA_KEY_FILE_FORMAT_RAW, NULL,
- &aes_key_data, &aes_key_data_len);
+ &aes_key_data, &aes_key_data_len);
if (ret != YACA_ERROR_NONE)
goto exit;
ret = yaca_simple_encrypt(YACA_ENCRYPT_AES, YACA_BCM_WRAP, key, iv,
- aes_key_data, aes_key_data_len,
- &wrapped_key_data, &wrapped_key_data_len);
+ aes_key_data, aes_key_data_len,
+ &wrapped_key_data, &wrapped_key_data_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Key unwrapping */
{
ret = yaca_simple_decrypt(YACA_ENCRYPT_AES, YACA_BCM_WRAP, key, iv,
- wrapped_key_data, wrapped_key_data_len,
- &aes_key_data, &aes_key_data_len);
+ wrapped_key_data, wrapped_key_data_len,
+ &aes_key_data, &aes_key_data_len);
if (ret != YACA_ERROR_NONE)
goto exit;
ret = yaca_key_import(YACA_KEY_TYPE_SYMMETRIC, NULL, aes_key_data, aes_key_data_len,
- &aes_key);
+ &aes_key);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Encryption */
{
ret = yaca_rsa_private_encrypt(YACA_PADDING_PKCS1, rsa_priv, INPUT_DATA, input_len,
- &encrypted, &encrypted_len);
+ &encrypted, &encrypted_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Decryption */
{
ret = yaca_rsa_public_decrypt(YACA_PADDING_PKCS1, rsa_pub, encrypted, encrypted_len,
- &decrypted, &decrypted_len);
+ &decrypted, &decrypted_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Encryption */
{
ret = yaca_rsa_public_encrypt(YACA_PADDING_PKCS1, rsa_pub, INPUT_DATA, input_len,
- &encrypted, &encrypted_len);
+ &encrypted, &encrypted_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Decryption */
{
ret = yaca_rsa_private_decrypt(YACA_PADDING_PKCS1, rsa_priv, encrypted, encrypted_len,
- &decrypted, &decrypted_len);
+ &decrypted, &decrypted_len);
if (ret != YACA_ERROR_NONE)
goto exit;
{
/* Initialize encryption context */
ret = yaca_seal_initialize(&ctx, rsa_pub, YACA_ENCRYPT_AES, YACA_BCM_CBC,
- YACA_KEY_LENGTH_256BIT, &sym_key, &iv);
+ YACA_KEY_LENGTH_256BIT, &sym_key, &iv);
if (ret != YACA_ERROR_NONE)
goto exit;
{
/* Initialize decryption context */
ret = yaca_open_initialize(&ctx, rsa_priv, YACA_ENCRYPT_AES, YACA_BCM_CBC,
- YACA_KEY_LENGTH_256BIT, sym_key, iv);
+ YACA_KEY_LENGTH_256BIT, sym_key, iv);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Sign */
{
ret = yaca_simple_calculate_signature(YACA_DIGEST_SHA384, priv_key,
- INPUT_DATA, INPUT_DATA_SIZE,
- &signature, &signature_len);
+ INPUT_DATA, INPUT_DATA_SIZE,
+ &signature, &signature_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Verify */
{
ret = yaca_simple_verify_signature(YACA_DIGEST_SHA384, pub_key,
- INPUT_DATA, INPUT_DATA_SIZE,
- signature, signature_len);
+ INPUT_DATA, INPUT_DATA_SIZE,
+ signature, signature_len);
if (ret != YACA_ERROR_NONE) {
printf("Verification failed\n");
goto exit;
/* Sign */
{
ret = yaca_simple_calculate_cmac(YACA_ENCRYPT_AES, sym_key,
- INPUT_DATA, INPUT_DATA_SIZE,
- &signature1, &signature_len);
+ INPUT_DATA, INPUT_DATA_SIZE,
+ &signature1, &signature_len);
if (ret != YACA_ERROR_NONE)
goto exit;
/* Verify */
{
ret = yaca_simple_calculate_cmac(YACA_ENCRYPT_AES, sym_key,
- INPUT_DATA, INPUT_DATA_SIZE,
- &signature2, &signature_len);
+ INPUT_DATA, INPUT_DATA_SIZE,
+ &signature2, &signature_len);
if (ret != YACA_ERROR_NONE)
goto exit;
if (CRYPTO_num_locks() > 0) {
ret = yaca_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t),
- (void**)&mutexes);
+ (void**)&mutexes);
if (ret != YACA_ERROR_NONE)
goto exit;
}
API int yaca_context_set_property(yaca_context_h ctx, yaca_property_e property,
- const void *value, size_t value_len)
+ const void *value, size_t value_len)
{
if (ctx == YACA_CONTEXT_NULL || ctx->set_property == NULL)
return YACA_ERROR_INVALID_PARAMETER;
}
API int yaca_context_get_property(const yaca_context_h ctx, yaca_property_e property,
- void **value, size_t *value_len)
+ void **value, size_t *value_len)
{
if (ctx == YACA_CONTEXT_NULL || ctx->get_property == NULL)
return YACA_ERROR_INVALID_PARAMETER;
}
API int yaca_context_get_output_length(const yaca_context_h ctx,
- size_t input_len, size_t *output_len)
+ size_t input_len, size_t *output_len)
{
if (ctx == YACA_CONTEXT_NULL || output_len == NULL ||
- ctx->get_output_length == NULL)
+ ctx->get_output_length == NULL)
return YACA_ERROR_INVALID_PARAMETER;
return ctx->get_output_length(ctx, input_len, output_len);
}
written = snprintf(buf, BUF_SIZE, "%s:%d %s() API error: %s0x%02X (%s)\n", file,
- line, function, sign, code, err_str);
+ line, function, sign, code, err_str);
while ((err = ERR_get_error()) != 0 && written < BUF_SIZE - 1) {
if (!error_strings_loaded) {
while ((err = ERR_get_error()) != 0)
if (err == ERR_PACK(ERR_LIB_PKCS12, PKCS12_F_PKCS12_ITEM_DECRYPT_D2I, PKCS12_R_DECODE_ERROR) ||
- err == ERR_PACK(ERR_LIB_PKCS12, PKCS12_F_PKCS12_PBE_CRYPT, PKCS12_R_PKCS12_CIPHERFINAL_ERROR) ||
- err == ERR_PACK(ERR_LIB_DSA, DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB) ||
- err == ERR_PACK(ERR_LIB_RSA, RSA_F_OLD_RSA_PRIV_DECODE, ERR_R_RSA_LIB)) {
+ err == ERR_PACK(ERR_LIB_PKCS12, PKCS12_F_PKCS12_PBE_CRYPT, PKCS12_R_PKCS12_CIPHERFINAL_ERROR) ||
+ err == ERR_PACK(ERR_LIB_DSA, DSA_F_OLD_DSA_PRIV_DECODE, ERR_R_DSA_LIB) ||
+ err == ERR_PACK(ERR_LIB_RSA, RSA_F_OLD_RSA_PRIV_DECODE, ERR_R_RSA_LIB)) {
found_crypto_error = true;
break;
}
}
static int get_digest_output_length(const yaca_context_h ctx,
- size_t input_len,
- size_t *output_len)
+ size_t input_len,
+ size_t *output_len)
{
assert(output_len != NULL);
}
static int encrypt_ctx_create(struct yaca_encrypt_context_s **c,
- enum encrypt_op_type_e op_type,
- const EVP_CIPHER *cipher)
+ enum encrypt_op_type_e op_type,
+ const EVP_CIPHER *cipher)
{
int ret;
int mode;
nc->backup_ctx = NULL;
nc->ctx.context_destroy = destroy_encrypt_context;
nc->ctx.get_output_length = (mode == EVP_CIPH_WRAP_MODE) ?
- get_wrap_output_length :
- get_encrypt_output_length;
+ get_wrap_output_length :
+ get_encrypt_output_length;
nc->ctx.set_property = set_encrypt_property;
nc->ctx.get_property = get_encrypt_property;
nc->op_type = op_type;
}
static int encrypt_ctx_init(struct yaca_encrypt_context_s *c,
- const EVP_CIPHER *cipher,
- size_t key_bit_len)
+ const EVP_CIPHER *cipher,
+ size_t key_bit_len)
{
int ret;
return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_CipherInit_ex(c->cipher_ctx,
- cipher,
- NULL,
- NULL,
- NULL,
- is_encryption_op(c->op_type) ? 1 : 0);
+ cipher,
+ NULL,
+ NULL,
+ NULL,
+ is_encryption_op(c->op_type) ? 1 : 0);
if (ret != 1) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
}
static int encrypt_ctx_setup_iv(struct yaca_encrypt_context_s *c,
- const EVP_CIPHER *cipher,
- const struct yaca_key_simple_s *iv)
+ const EVP_CIPHER *cipher,
+ const struct yaca_key_simple_s *iv)
{
int ret;
size_t default_iv_bit_len;
if (mode == EVP_CIPH_GCM_MODE) {
ret = EVP_CIPHER_CTX_ctrl(c->cipher_ctx, EVP_CTRL_GCM_SET_IVLEN,
- iv->bit_len / 8, NULL);
+ iv->bit_len / 8, NULL);
} else if (mode == EVP_CIPH_CCM_MODE) {
ret = EVP_CIPHER_CTX_ctrl(c->cipher_ctx, EVP_CTRL_CCM_SET_IVLEN,
- iv->bit_len / 8, NULL);
+ iv->bit_len / 8, NULL);
} else {
return YACA_ERROR_INVALID_PARAMETER;
}
}
static int encrypt_ctx_setup(struct yaca_encrypt_context_s *c,
- const yaca_key_h key,
- const yaca_key_h iv)
+ const yaca_key_h key,
+ const yaca_key_h iv)
{
int ret;
unsigned char *iv_data = NULL;
iv_data = (unsigned char*)liv->d;
ret = EVP_CipherInit_ex(c->cipher_ctx,
- NULL,
- NULL,
- (unsigned char*)lkey->d,
- iv_data,
- is_encryption_op(c->op_type) ? 1 : 0);
+ NULL,
+ NULL,
+ (unsigned char*)lkey->d,
+ iv_data,
+ is_encryption_op(c->op_type) ? 1 : 0);
if (ret != 1) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
}
static int encrypt_ctx_backup(struct yaca_encrypt_context_s *c,
- const EVP_CIPHER *cipher,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+ const EVP_CIPHER *cipher,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
int ret;
struct yaca_backup_context_s *bc;
assert(ret != YACA_ERROR_INVALID_PARAMETER);
if (c->backup_ctx->padding == YACA_PADDING_NONE &&
- EVP_CIPHER_CTX_set_padding(c->cipher_ctx, 0) != 1) {
+ EVP_CIPHER_CTX_set_padding(c->cipher_ctx, 0) != 1) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
return ret;
}
int set_encrypt_property(yaca_context_h ctx,
- yaca_property_e property,
- const void *value,
- size_t value_len)
+ yaca_property_e property,
+ const void *value,
+ size_t value_len)
{
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int len;
switch (property) {
case YACA_PROPERTY_GCM_AAD:
if (mode != EVP_CIPH_GCM_MODE ||
- !verify_state_change(c, ENC_CTX_AAD_UPDATED))
+ !verify_state_change(c, ENC_CTX_AAD_UPDATED))
return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CipherUpdate(c->cipher_ctx, NULL, &len, value, value_len) != 1) {
break;
case YACA_PROPERTY_CCM_AAD:
if (mode != EVP_CIPH_CCM_MODE ||
- !verify_state_change(c, ENC_CTX_AAD_UPDATED))
+ !verify_state_change(c, ENC_CTX_AAD_UPDATED))
return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CipherUpdate(c->cipher_ctx, NULL, &len, value, value_len) != 1) {
break;
case YACA_PROPERTY_GCM_TAG:
if (mode != EVP_CIPH_GCM_MODE || is_encryption_op(c->op_type) ||
- !is_valid_tag_len(mode, value_len) ||
- !verify_state_change(c, ENC_CTX_TAG_SET))
+ !is_valid_tag_len(mode, value_len) ||
+ !verify_state_change(c, ENC_CTX_TAG_SET))
return YACA_ERROR_INVALID_PARAMETER;
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx, EVP_CTRL_GCM_SET_TAG, value_len, (void*)value) != 1) {
break;
case YACA_PROPERTY_GCM_TAG_LEN:
if (value_len != sizeof(size_t) || mode != EVP_CIPH_GCM_MODE ||
- !is_encryption_op(c->op_type) ||
- !is_valid_tag_len(mode, *(size_t*)value) ||
- !verify_state_change(c, ENC_CTX_TAG_LENGTH_SET))
+ !is_encryption_op(c->op_type) ||
+ !is_valid_tag_len(mode, *(size_t*)value) ||
+ !verify_state_change(c, ENC_CTX_TAG_LENGTH_SET))
return YACA_ERROR_INVALID_PARAMETER;
c->tag_len = *(size_t*)value;
break;
case YACA_PROPERTY_CCM_TAG:
if (mode != EVP_CIPH_CCM_MODE || is_encryption_op(c->op_type) ||
- !is_valid_tag_len(mode, value_len) ||
- !verify_state_change(c, ENC_CTX_TAG_SET))
+ !is_valid_tag_len(mode, value_len) ||
+ !verify_state_change(c, ENC_CTX_TAG_SET))
return YACA_ERROR_INVALID_PARAMETER;
ret = encrypt_ctx_set_ccm_tag(c, (char*)value, value_len);
break;
case YACA_PROPERTY_CCM_TAG_LEN:
if (value_len != sizeof(size_t) || mode != EVP_CIPH_CCM_MODE ||
- !is_encryption_op(c->op_type) ||
- !is_valid_tag_len(mode, *(size_t*)value) ||
- !verify_state_change(c, ENC_CTX_TAG_LENGTH_SET))
+ !is_encryption_op(c->op_type) ||
+ !is_valid_tag_len(mode, *(size_t*)value) ||
+ !verify_state_change(c, ENC_CTX_TAG_LENGTH_SET))
return YACA_ERROR_INVALID_PARAMETER;
ret = encrypt_ctx_set_ccm_tag_len(c, *(size_t*)value);
break;
case YACA_PROPERTY_PADDING:
if ((mode != EVP_CIPH_ECB_MODE && mode != EVP_CIPH_CBC_MODE) ||
- value_len != sizeof(yaca_padding_e) ||
- (*(yaca_padding_e*)value != YACA_PADDING_NONE &&
- *(yaca_padding_e*)value != YACA_PADDING_PKCS7) ||
- c->state == ENC_CTX_FINALIZED)
+ value_len != sizeof(yaca_padding_e) ||
+ (*(yaca_padding_e*)value != YACA_PADDING_NONE &&
+ *(yaca_padding_e*)value != YACA_PADDING_PKCS7) ||
+ c->state == ENC_CTX_FINALIZED)
return YACA_ERROR_INVALID_PARAMETER;
int padding = *(yaca_padding_e*)value == YACA_PADDING_NONE ? 0 : 1;
break;
case YACA_PROPERTY_RC2_EFFECTIVE_KEY_BITS:
if (value_len != sizeof(size_t) ||
- (nid != NID_rc2_cbc && nid != NID_rc2_ecb && nid != NID_rc2_cfb64 && nid != NID_rc2_ofb64) ||
- c->state != ENC_CTX_INITIALIZED)
+ (nid != NID_rc2_cbc && nid != NID_rc2_ecb && nid != NID_rc2_cfb64 && nid != NID_rc2_ofb64) ||
+ c->state != ENC_CTX_INITIALIZED)
return YACA_ERROR_INVALID_PARAMETER;
ret = encrypt_ctx_set_rc2_effective_key_bits(c, *(size_t*)value);
}
int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
- void **value, size_t *value_len)
+ void **value, size_t *value_len)
{
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int mode;
switch (property) {
case YACA_PROPERTY_GCM_TAG:
if (value_len == NULL ||
- !is_encryption_op(c->op_type) ||
- mode != EVP_CIPH_GCM_MODE ||
- (c->state != ENC_CTX_TAG_LENGTH_SET && c->state != ENC_CTX_FINALIZED))
+ !is_encryption_op(c->op_type) ||
+ mode != EVP_CIPH_GCM_MODE ||
+ (c->state != ENC_CTX_TAG_LENGTH_SET && c->state != ENC_CTX_FINALIZED))
return YACA_ERROR_INVALID_PARAMETER;
assert(c->tag_len <= INT_MAX);
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
- EVP_CTRL_GCM_GET_TAG,
- c->tag_len,
- value) != 1) {
+ EVP_CTRL_GCM_GET_TAG,
+ c->tag_len,
+ value) != 1) {
ERROR_DUMP(YACA_ERROR_INTERNAL);
return YACA_ERROR_INTERNAL;
}
break;
case YACA_PROPERTY_CCM_TAG:
if (value_len == NULL ||
- !is_encryption_op(c->op_type) ||
- mode != EVP_CIPH_CCM_MODE ||
- c->state != ENC_CTX_FINALIZED)
+ !is_encryption_op(c->op_type) ||
+ mode != EVP_CIPH_CCM_MODE ||
+ c->state != ENC_CTX_FINALIZED)
return YACA_ERROR_INVALID_PARAMETER;
assert(c->tag_len <= INT_MAX);
if (EVP_CIPHER_CTX_ctrl(c->cipher_ctx,
- EVP_CTRL_CCM_GET_TAG,
- c->tag_len,
- value) != 1) {
+ EVP_CTRL_CCM_GET_TAG,
+ c->tag_len,
+ value) != 1) {
ERROR_DUMP(YACA_ERROR_INTERNAL);
return YACA_ERROR_INTERNAL;
}
switch (algo) {
case YACA_ENCRYPT_AES:
if (key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
- key_bit_len != YACA_KEY_LENGTH_192BIT &&
- key_bit_len != YACA_KEY_LENGTH_256BIT)
+ key_bit_len != YACA_KEY_LENGTH_192BIT &&
+ key_bit_len != YACA_KEY_LENGTH_256BIT)
ret = YACA_ERROR_INVALID_PARAMETER;
break;
case YACA_ENCRYPT_UNSAFE_DES:
}
int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bit_len,
- const EVP_CIPHER **cipher)
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bit_len,
+ const EVP_CIPHER **cipher)
{
int ret;
size_t i;
for (i = 0; i < ENCRYPTION_CIPHERS_SIZE; ++i)
if (ENCRYPTION_CIPHERS[i].algo == algo &&
- ENCRYPTION_CIPHERS[i].bcm == bcm &&
- (ENCRYPTION_CIPHERS[i].key_bit_len == key_bit_len ||
- ENCRYPTION_CIPHERS[i].key_bit_len == (size_t)-1)) {
+ ENCRYPTION_CIPHERS[i].bcm == bcm &&
+ (ENCRYPTION_CIPHERS[i].key_bit_len == key_bit_len ||
+ ENCRYPTION_CIPHERS[i].key_bit_len == (size_t)-1)) {
*cipher = ENCRYPTION_CIPHERS[i].cipher();
ret = YACA_ERROR_NONE;
break;
}
int encrypt_initialize(yaca_context_h *ctx,
- const EVP_CIPHER *cipher,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- enum encrypt_op_type_e op_type)
+ const EVP_CIPHER *cipher,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ enum encrypt_op_type_e op_type)
{
struct yaca_encrypt_context_s *nc;
struct yaca_key_simple_s *lsym_key;
return YACA_ERROR_INVALID_PARAMETER;
if (lsym_key->key.type != YACA_KEY_TYPE_DES &&
- lsym_key->key.type != YACA_KEY_TYPE_SYMMETRIC)
+ lsym_key->key.type != YACA_KEY_TYPE_SYMMETRIC)
return YACA_ERROR_INVALID_PARAMETER;
ret = encrypt_ctx_create(&nc, op_type, cipher);
int mode = EVP_CIPHER_CTX_mode(nc->cipher_ctx);
int nid = EVP_CIPHER_CTX_nid(nc->cipher_ctx);
if (mode == EVP_CIPH_CCM_MODE ||
- nid == NID_rc2_cbc || nid == NID_rc2_ecb || nid == NID_rc2_cfb64 || nid == NID_rc2_ofb64) {
+ nid == NID_rc2_cbc || nid == NID_rc2_ecb || nid == NID_rc2_cfb64 || nid == NID_rc2_ofb64) {
ret = encrypt_ctx_backup(nc, cipher, sym_key, iv);
if (ret != YACA_ERROR_NONE)
goto exit;
}
int encrypt_update(yaca_context_h ctx,
- const unsigned char *input, size_t input_len,
- unsigned char *output, size_t *output_len,
- enum encrypt_op_type_e op_type)
+ const unsigned char *input, size_t input_len,
+ unsigned char *output, size_t *output_len,
+ enum encrypt_op_type_e op_type)
{
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int ret;
return YACA_ERROR_INVALID_PARAMETER;
} else if (nid == NID_id_smime_alg_CMS3DESwrap) {
if (input_len != (YACA_KEY_LENGTH_UNSAFE_128BIT / 8) &&
- input_len != (YACA_KEY_LENGTH_192BIT / 8))
+ input_len != (YACA_KEY_LENGTH_192BIT / 8))
return YACA_ERROR_INVALID_PARAMETER;
} else {
assert(false);
return YACA_ERROR_INVALID_PARAMETER;
} else if (nid == NID_id_smime_alg_CMS3DESwrap) {
if (input_len != (YACA_KEY_LENGTH_UNSAFE_128BIT / 8 + 16) &&
- input_len != (YACA_KEY_LENGTH_192BIT / 8 + 16))
+ input_len != (YACA_KEY_LENGTH_192BIT / 8 + 16))
return YACA_ERROR_INVALID_PARAMETER;
} else {
assert(false);
}
int encrypt_finalize(yaca_context_h ctx,
- unsigned char *output, size_t *output_len,
- enum encrypt_op_type_e op_type)
+ unsigned char *output, size_t *output_len,
+ enum encrypt_op_type_e op_type)
{
struct yaca_encrypt_context_s *c = get_encrypt_context(ctx);
int ret;
}
API int yaca_encrypt_get_iv_bit_length(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bit_len,
- size_t *iv_bit_len)
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bit_len,
+ size_t *iv_bit_len)
{
const EVP_CIPHER *cipher;
int ret;
}
API int yaca_encrypt_initialize(yaca_context_h *ctx,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
int ret;
const EVP_CIPHER *cipher;
}
API int yaca_encrypt_update(yaca_context_h ctx,
- const char *plaintext,
- size_t plaintext_len,
- char *ciphertext,
- size_t *ciphertext_len)
+ const char *plaintext,
+ size_t plaintext_len,
+ char *ciphertext,
+ size_t *ciphertext_len)
{
return encrypt_update(ctx, (const unsigned char*)plaintext, plaintext_len,
- (unsigned char*)ciphertext, ciphertext_len, OP_ENCRYPT);
+ (unsigned char*)ciphertext, ciphertext_len, OP_ENCRYPT);
}
API int yaca_encrypt_finalize(yaca_context_h ctx,
- char *ciphertext,
- size_t *ciphertext_len)
+ char *ciphertext,
+ size_t *ciphertext_len)
{
return encrypt_finalize(ctx, (unsigned char*)ciphertext, ciphertext_len, OP_ENCRYPT);
}
API int yaca_decrypt_initialize(yaca_context_h *ctx,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
int ret;
const EVP_CIPHER *cipher;
}
API int yaca_decrypt_update(yaca_context_h ctx,
- const char *ciphertext,
- size_t ciphertext_len,
- char *plaintext,
- size_t *plaintext_len)
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char *plaintext,
+ size_t *plaintext_len)
{
return encrypt_update(ctx, (const unsigned char*)ciphertext, ciphertext_len,
- (unsigned char*)plaintext, plaintext_len, OP_DECRYPT);
+ (unsigned char*)plaintext, plaintext_len, OP_DECRYPT);
}
API int yaca_decrypt_finalize(yaca_context_h ctx,
- char *plaintext,
- size_t *plaintext_len)
+ char *plaintext,
+ size_t *plaintext_len)
{
return encrypt_finalize(ctx, (unsigned char*)plaintext, plaintext_len, OP_DECRYPT);
}
void (*context_destroy)(const yaca_context_h ctx);
int (*get_output_length)(const yaca_context_h ctx, size_t input_len, size_t *output_len);
int (*set_property)(yaca_context_h ctx, yaca_property_e property,
- const void *value, size_t value_len);
+ const void *value, size_t value_len);
int (*get_property)(const yaca_context_h ctx, yaca_property_e property,
- void **value, size_t *value_len);
+ void **value, size_t *value_len);
};
struct yaca_backup_context_s {
int get_encrypt_output_length(const yaca_context_h ctx, size_t input_len, size_t *output_len);
int set_encrypt_property(yaca_context_h ctx, yaca_property_e property,
- const void *value, size_t value_len);
+ const void *value, size_t value_len);
int get_encrypt_property(const yaca_context_h ctx, yaca_property_e property,
- void **value, size_t *value_len);
+ void **value, size_t *value_len);
int encrypt_get_algorithm(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bit_len,
- const EVP_CIPHER **cipher);
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bit_len,
+ const EVP_CIPHER **cipher);
int encrypt_initialize(yaca_context_h *ctx,
- const EVP_CIPHER *cipher,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- enum encrypt_op_type_e op_type);
+ const EVP_CIPHER *cipher,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ enum encrypt_op_type_e op_type);
int encrypt_update(yaca_context_h ctx,
- const unsigned char *input, size_t input_len,
- unsigned char *output, size_t *output_len,
- enum encrypt_op_type_e op_type);
+ const unsigned char *input, size_t input_len,
+ unsigned char *output, size_t *output_len,
+ enum encrypt_op_type_e op_type);
int encrypt_finalize(yaca_context_h ctx,
- unsigned char *output, size_t *output_len,
- enum encrypt_op_type_e op_type);
+ unsigned char *output, size_t *output_len,
+ enum encrypt_op_type_e op_type);
struct yaca_key_simple_s *key_get_simple(const yaca_key_h key);
struct yaca_key_evp_s *key_get_evp(const yaca_key_h key);
}
static int import_simple(yaca_key_h *key,
- yaca_key_type_e key_type,
- const char *data,
- size_t data_len)
+ yaca_key_type_e key_type,
+ const char *data,
+ size_t data_len)
{
assert(key != NULL);
assert(data != NULL);
if (key_type == YACA_KEY_TYPE_DES) {
size_t key_bit_len = key_data_len * 8;
if (key_bit_len != YACA_KEY_LENGTH_UNSAFE_64BIT &&
- key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
- key_bit_len != YACA_KEY_LENGTH_192BIT) {
+ key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
+ key_bit_len != YACA_KEY_LENGTH_192BIT) {
ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
}
static int import_evp(yaca_key_h *key,
- yaca_key_type_e key_type,
- const char *password,
- const char *data,
- size_t data_len)
+ yaca_key_type_e key_type,
+ const char *password,
+ const char *data,
+ size_t data_len)
{
assert(key != NULL);
assert(password == NULL || password[0] != '\0');
}
if ((key_type == YACA_KEY_TYPE_RSA_PRIV || key_type == YACA_KEY_TYPE_RSA_PUB) &&
- (EVP_PKEY_size(pkey) < YACA_KEY_LENGTH_512BIT / 8)) {
+ (EVP_PKEY_size(pkey) < YACA_KEY_LENGTH_512BIT / 8)) {
ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
}
static int export_simple_raw(struct yaca_key_simple_s *simple_key,
- char **data,
- size_t *data_len)
+ char **data,
+ size_t *data_len)
{
int ret;
assert(simple_key != NULL);
}
static int export_simple_base64(struct yaca_key_simple_s *simple_key,
- char **data,
- size_t *data_len)
+ char **data,
+ size_t *data_len)
{
assert(simple_key != NULL);
assert(data != NULL);
}
static int export_evp_default_bio(struct yaca_key_evp_s *evp_key,
- yaca_key_file_format_e key_file_fmt,
- const char *password,
- BIO *mem)
+ yaca_key_file_format_e key_file_fmt,
+ const char *password,
+ BIO *mem)
{
assert(evp_key != NULL);
assert(password == NULL || password[0] != '\0');
case YACA_KEY_TYPE_DH_PRIV:
case YACA_KEY_TYPE_EC_PRIV:
ret = PEM_write_bio_PrivateKey(mem, evp_key->evp, enc,
- NULL, 0, NULL, (void*)password);
+ NULL, 0, NULL, (void*)password);
break;
case YACA_KEY_TYPE_RSA_PUB:
}
static int export_evp_pkcs8_bio(struct yaca_key_evp_s *evp_key,
- yaca_key_file_format_e key_file_fmt,
- const char *password,
- BIO *mem)
+ yaca_key_file_format_e key_file_fmt,
+ const char *password,
+ BIO *mem)
{
assert(evp_key != NULL);
assert(password == NULL || password[0] != '\0');
case YACA_KEY_TYPE_DH_PRIV:
case YACA_KEY_TYPE_EC_PRIV:
ret = PEM_write_bio_PKCS8PrivateKey(mem, evp_key->evp, enc,
- NULL, 0, NULL, (void*)password);
+ NULL, 0, NULL, (void*)password);
break;
default:
case YACA_KEY_TYPE_DH_PRIV:
case YACA_KEY_TYPE_EC_PRIV:
ret = i2d_PKCS8PrivateKey_bio(mem, evp_key->evp, enc,
- NULL, 0, NULL, (void*)password);
+ NULL, 0, NULL, (void*)password);
break;
default:
}
static int export_evp(struct yaca_key_evp_s *evp_key,
- yaca_key_format_e key_fmt,
- yaca_key_file_format_e key_file_fmt,
- const char *password,
- char **data,
- size_t *data_len)
+ yaca_key_format_e key_fmt,
+ yaca_key_file_format_e key_file_fmt,
+ const char *password,
+ char **data,
+ size_t *data_len)
{
assert(evp_key != NULL);
assert(password == NULL || password[0] != '\0');
assert(out != NULL);
if (key_bit_len != YACA_KEY_LENGTH_UNSAFE_64BIT &&
- key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
- key_bit_len != YACA_KEY_LENGTH_192BIT)
+ key_bit_len != YACA_KEY_LENGTH_UNSAFE_128BIT &&
+ key_bit_len != YACA_KEY_LENGTH_192BIT)
return YACA_ERROR_INVALID_PARAMETER;
int ret;
switch (evp_id) {
case EVP_PKEY_DSA:
if ((key_bit_len & YACA_KEYLEN_COMPONENT_TYPE_MASK) != YACA_KEYLEN_COMPONENT_TYPE_BITS ||
- key_bit_len > INT_MAX || key_bit_len < 512 || key_bit_len % 64 != 0)
+ key_bit_len > INT_MAX || key_bit_len < 512 || key_bit_len % 64 != 0)
return YACA_ERROR_INVALID_PARAMETER;
bit_len = key_bit_len;
* fact that the _set_dh_ variant actually passes EVP_PKEY_DHX:
* ret = EVP_PKEY_CTX_set_dh_rfc5114(pctx, dh_rfc5114); */
ret = EVP_PKEY_CTX_ctrl(pctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN,
- EVP_PKEY_CTRL_DH_RFC5114, dh_rfc5114, NULL);
+ EVP_PKEY_CTRL_DH_RFC5114, dh_rfc5114, NULL);
} else {
ret = EVP_PKEY_CTX_set_dh_paramgen_prime_len(pctx, dh_prime_len);
if (ret == 1)
if (evp_id == EVP_PKEY_RSA) {
if ((key_bit_len & YACA_KEYLEN_COMPONENT_TYPE_MASK) != YACA_KEYLEN_COMPONENT_TYPE_BITS ||
- key_bit_len > INT_MAX || key_bit_len < 512 || key_bit_len % 8 != 0) {
+ key_bit_len > INT_MAX || key_bit_len < 512 || key_bit_len % 8 != 0) {
ret = YACA_ERROR_INVALID_PARAMETER;
goto exit;
}
}
static int generate_evp(yaca_key_type_e out_type, size_t key_bit_len,
- struct yaca_key_evp_s *params, struct yaca_key_evp_s **out)
+ struct yaca_key_evp_s *params, struct yaca_key_evp_s **out)
{
assert(out != NULL);
assert(key_bit_len > 0 || params != NULL);
}
API int yaca_key_import(yaca_key_type_e key_type,
- const char *password,
- const char *data,
- size_t data_len,
- yaca_key_h *key)
+ const char *password,
+ const char *data,
+ size_t data_len,
+ yaca_key_h *key)
{
if (key == NULL || data == NULL || data_len == 0)
return YACA_ERROR_INVALID_PARAMETER;
}
API int yaca_key_export(const yaca_key_h key,
- yaca_key_format_e key_fmt,
- yaca_key_file_format_e key_file_fmt,
- const char *password,
- char **data,
- size_t *data_len)
+ yaca_key_format_e key_fmt,
+ yaca_key_file_format_e key_file_fmt,
+ const char *password,
+ char **data,
+ size_t *data_len)
{
struct yaca_key_simple_s *simple_key = key_get_simple(key);
struct yaca_key_evp_s *evp_key = key_get_evp(key);
return YACA_ERROR_INVALID_PARAMETER;
if (key_fmt == YACA_KEY_FORMAT_DEFAULT &&
- key_file_fmt == YACA_KEY_FILE_FORMAT_RAW &&
- simple_key != NULL)
+ key_file_fmt == YACA_KEY_FILE_FORMAT_RAW &&
+ simple_key != NULL)
return export_simple_raw(simple_key, data, data_len);
if (key_fmt == YACA_KEY_FORMAT_DEFAULT &&
- key_file_fmt == YACA_KEY_FILE_FORMAT_BASE64 &&
- simple_key != NULL)
+ key_file_fmt == YACA_KEY_FILE_FORMAT_BASE64 &&
+ simple_key != NULL)
return export_simple_base64(simple_key, data, data_len);
if (evp_key != NULL)
return export_evp(evp_key, key_fmt, key_file_fmt,
- password, data, data_len);
+ password, data, data_len);
return YACA_ERROR_INVALID_PARAMETER;
}
API int yaca_key_generate(yaca_key_type_e key_type,
- size_t key_bit_len,
- yaca_key_h *key)
+ size_t key_bit_len,
+ yaca_key_h *key)
{
int ret;
struct yaca_key_simple_s *nk_simple = NULL;
}
API int yaca_key_derive_dh(const yaca_key_h prv_key,
- const yaca_key_h pub_key,
- char **secret,
- size_t *secret_len)
+ const yaca_key_h pub_key,
+ char **secret,
+ size_t *secret_len)
{
int ret;
struct yaca_key_evp_s *lprv_key = key_get_evp(prv_key);
size_t data_len;
if (lprv_key == NULL || lpub_key == NULL || secret == NULL || secret_len == NULL ||
- (!(lprv_key->key.type == YACA_KEY_TYPE_DH_PRIV &&
- lpub_key->key.type == YACA_KEY_TYPE_DH_PUB)
- &&
- !(lprv_key->key.type == YACA_KEY_TYPE_EC_PRIV &&
- lpub_key->key.type == YACA_KEY_TYPE_EC_PUB)))
+ (!(lprv_key->key.type == YACA_KEY_TYPE_DH_PRIV &&
+ lpub_key->key.type == YACA_KEY_TYPE_DH_PUB)
+ &&
+ !(lprv_key->key.type == YACA_KEY_TYPE_EC_PRIV &&
+ lpub_key->key.type == YACA_KEY_TYPE_EC_PUB)))
return YACA_ERROR_INVALID_PARAMETER;
ctx = EVP_PKEY_CTX_new(lprv_key->evp, NULL);
}
API int yaca_key_derive_kdf(yaca_kdf_e kdf,
- yaca_digest_algorithm_e algo,
- const char *secret,
- size_t secret_len,
- const char *info,
- size_t info_len,
- size_t key_material_len,
- char **key_material)
+ yaca_digest_algorithm_e algo,
+ const char *secret,
+ size_t secret_len,
+ const char *info,
+ size_t info_len,
+ size_t key_material_len,
+ char **key_material)
{
int ret;
char *out = NULL;
const EVP_MD *md;
if (secret == NULL || secret_len == 0 ||
- (info == NULL && info_len > 0) || (info != NULL && info_len == 0) ||
- key_material_len == 0 || key_material == NULL)
+ (info == NULL && info_len > 0) || (info != NULL && info_len == 0) ||
+ key_material_len == 0 || key_material == NULL)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(key_material_len, (void**)&out);
switch (kdf) {
case YACA_KDF_X942:
ret = DH_KDF_X9_42((unsigned char*)out, key_material_len,
- (unsigned char*)secret, secret_len,
- OBJ_nid2obj(NID_id_smime_alg_ESDH), (unsigned char*)info, info_len, md);
+ (unsigned char*)secret, secret_len,
+ OBJ_nid2obj(NID_id_smime_alg_ESDH), (unsigned char*)info, info_len, md);
if (ret != 1 || out == NULL) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
break;
case YACA_KDF_X962:
ret = ECDH_KDF_X9_62((unsigned char*)out, key_material_len,
- (unsigned char*)secret, secret_len,
- (unsigned char*)info, info_len, md);
+ (unsigned char*)secret, secret_len,
+ (unsigned char*)info, info_len, md);
if (ret != 1 || out == NULL) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
}
API int yaca_key_derive_pbkdf2(const char *password,
- const char *salt,
- size_t salt_len,
- size_t iterations,
- yaca_digest_algorithm_e algo,
- size_t key_bit_len,
- yaca_key_h *key)
+ const char *salt,
+ size_t salt_len,
+ size_t iterations,
+ yaca_digest_algorithm_e algo,
+ size_t key_bit_len,
+ yaca_key_h *key)
{
const EVP_MD *md;
struct yaca_key_simple_s *nk;
int ret;
if (password == NULL ||
- (salt == NULL && salt_len > 0) || (salt != NULL && salt_len == 0) ||
- iterations == 0 || key_bit_len == 0 || key == NULL)
+ (salt == NULL && salt_len > 0) || (salt != NULL && salt_len == 0) ||
+ iterations == 0 || key_bit_len == 0 || key == NULL)
return YACA_ERROR_INVALID_PARAMETER;
if (key_bit_len % 8) /* Key length must be multiple of 8-bit_len */
nk->key.type = YACA_KEY_TYPE_SYMMETRIC;
ret = PKCS5_PBKDF2_HMAC(password, -1, (const unsigned char*)salt,
- salt_len, iterations, md, key_byte_len,
- (unsigned char*)nk->d);
+ salt_len, iterations, md, key_byte_len,
+ (unsigned char*)nk->d);
if (ret != 1) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
typedef int (*encrypt_decrypt_fn)(int, const unsigned char*, unsigned char*, RSA*, int);
static int encrypt_decrypt(yaca_padding_e padding,
- const yaca_key_h key,
- const char *input,
- size_t input_len,
- char **output,
- size_t *output_len,
- encrypt_decrypt_fn fn)
+ const yaca_key_h key,
+ const char *input,
+ size_t input_len,
+ char **output,
+ size_t *output_len,
+ encrypt_decrypt_fn fn)
{
int ret;
size_t max_len;
int lpadding;
if ((input == NULL && input_len > 0) || (input != NULL && input_len == 0) ||
- output == NULL || output_len == NULL)
+ output == NULL || output_len == NULL)
return YACA_ERROR_INVALID_PARAMETER;
lpadding = rsa_padding2openssl(padding);
return ret;
ret = fn(input_len,
- (const unsigned char*)input,
- (unsigned char*)loutput,
- EVP_PKEY_get0_RSA(lasym_key->evp),
- lpadding);
+ (const unsigned char*)input,
+ (unsigned char*)loutput,
+ EVP_PKEY_get0_RSA(lasym_key->evp),
+ lpadding);
if (ret < 0) {
ret = ERROR_HANDLE();
API int yaca_rsa_public_encrypt(yaca_padding_e padding,
- const yaca_key_h pub_key,
- const char *plaintext,
- size_t plaintext_len,
- char **ciphertext,
- size_t *ciphertext_len)
+ const yaca_key_h pub_key,
+ const char *plaintext,
+ size_t plaintext_len,
+ char **ciphertext,
+ size_t *ciphertext_len)
{
if (pub_key == YACA_KEY_NULL || pub_key->type != YACA_KEY_TYPE_RSA_PUB)
return YACA_ERROR_INVALID_PARAMETER;
}
return encrypt_decrypt(padding,
- pub_key,
- plaintext,
- plaintext_len,
- ciphertext,
- ciphertext_len,
- RSA_public_encrypt);
+ pub_key,
+ plaintext,
+ plaintext_len,
+ ciphertext,
+ ciphertext_len,
+ RSA_public_encrypt);
}
API int yaca_rsa_private_decrypt(yaca_padding_e padding,
- const yaca_key_h prv_key,
- const char *ciphertext,
- size_t ciphertext_len,
- char **plaintext,
- size_t *plaintext_len)
+ const yaca_key_h prv_key,
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char **plaintext,
+ size_t *plaintext_len)
{
if (prv_key == YACA_KEY_NULL || prv_key->type != YACA_KEY_TYPE_RSA_PRIV)
return YACA_ERROR_INVALID_PARAMETER;
}
return encrypt_decrypt(padding,
- prv_key,
- ciphertext,
- ciphertext_len,
- plaintext,
- plaintext_len,
- RSA_private_decrypt);
+ prv_key,
+ ciphertext,
+ ciphertext_len,
+ plaintext,
+ plaintext_len,
+ RSA_private_decrypt);
}
API int yaca_rsa_private_encrypt(yaca_padding_e padding,
- const yaca_key_h prv_key,
- const char *plaintext,
- size_t plaintext_len,
- char **ciphertext,
- size_t *ciphertext_len)
+ const yaca_key_h prv_key,
+ const char *plaintext,
+ size_t plaintext_len,
+ char **ciphertext,
+ size_t *ciphertext_len)
{
if (prv_key == YACA_KEY_NULL || prv_key->type != YACA_KEY_TYPE_RSA_PRIV)
return YACA_ERROR_INVALID_PARAMETER;
}
return encrypt_decrypt(padding,
- prv_key,
- plaintext,
- plaintext_len,
- ciphertext,
- ciphertext_len,
- RSA_private_encrypt);
+ prv_key,
+ plaintext,
+ plaintext_len,
+ ciphertext,
+ ciphertext_len,
+ RSA_private_encrypt);
}
API int yaca_rsa_public_decrypt(yaca_padding_e padding,
- const yaca_key_h pub_key,
- const char *ciphertext,
- size_t ciphertext_len,
- char **plaintext,
- size_t *plaintext_len)
+ const yaca_key_h pub_key,
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char **plaintext,
+ size_t *plaintext_len)
{
if (pub_key == YACA_KEY_NULL || pub_key->type != YACA_KEY_TYPE_RSA_PUB)
return YACA_ERROR_INVALID_PARAMETER;
}
return encrypt_decrypt(padding,
- pub_key,
- ciphertext,
- ciphertext_len,
- plaintext,
- plaintext_len,
- RSA_public_decrypt);
+ pub_key,
+ ciphertext,
+ ciphertext_len,
+ plaintext,
+ plaintext_len,
+ RSA_public_decrypt);
}
#include "internal.h"
static int seal_generate_sym_key(yaca_encrypt_algorithm_e algo,
- size_t sym_key_bit_len,
- yaca_key_h *sym_key)
+ size_t sym_key_bit_len,
+ yaca_key_h *sym_key)
{
assert(sym_key != NULL);
if (algo == YACA_ENCRYPT_3DES_3TDEA ||
- algo == YACA_ENCRYPT_UNSAFE_3DES_2TDEA ||
- algo == YACA_ENCRYPT_UNSAFE_DES)
+ algo == YACA_ENCRYPT_UNSAFE_3DES_2TDEA ||
+ algo == YACA_ENCRYPT_UNSAFE_DES)
return yaca_key_generate(YACA_KEY_TYPE_DES, sym_key_bit_len, sym_key);
else
return yaca_key_generate(YACA_KEY_TYPE_SYMMETRIC, sym_key_bit_len, sym_key);
/* used for asymmetric encryption and decryption */
static int seal_encrypt_decrypt_key(const yaca_key_h asym_key,
- const yaca_key_h in_key,
- yaca_key_h *out_key)
+ const yaca_key_h in_key,
+ yaca_key_h *out_key)
{
int ret;
const struct yaca_key_evp_s *lasym_key;
if (asym_key->type == YACA_KEY_TYPE_RSA_PRIV)
ret = EVP_PKEY_decrypt_old((unsigned char*)lout_key->d,
- (unsigned char*)lin_key->d,
- lin_key->bit_len / 8,
- lasym_key->evp);
+ (unsigned char*)lin_key->d,
+ lin_key->bit_len / 8,
+ lasym_key->evp);
else
ret = EVP_PKEY_encrypt_old((unsigned char*)lout_key->d,
- (unsigned char*)lin_key->d,
- lin_key->bit_len / 8,
- lasym_key->evp);
+ (unsigned char*)lin_key->d,
+ lin_key->bit_len / 8,
+ lasym_key->evp);
if (ret <= 0) {
ret = ERROR_HANDLE();
}
API int yaca_seal_initialize(yaca_context_h *ctx,
- const yaca_key_h pub_key,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t sym_key_bit_len,
- yaca_key_h *sym_key,
- yaca_key_h *iv)
+ const yaca_key_h pub_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t sym_key_bit_len,
+ yaca_key_h *sym_key,
+ yaca_key_h *iv)
{
int ret;
const EVP_CIPHER *cipher;
yaca_key_h lenc_sym_key = YACA_KEY_NULL;
if (pub_key == YACA_KEY_NULL || pub_key->type != YACA_KEY_TYPE_RSA_PUB ||
- sym_key == NULL || bcm == YACA_BCM_WRAP || sym_key_bit_len % 8 != 0)
+ sym_key == NULL || bcm == YACA_BCM_WRAP || sym_key_bit_len % 8 != 0)
return YACA_ERROR_INVALID_PARAMETER;
ret = encrypt_get_algorithm(algo, bcm, sym_key_bit_len, &cipher);
}
API int yaca_seal_update(yaca_context_h ctx,
- const char *plaintext,
- size_t plaintext_len,
- char *ciphertext,
- size_t *ciphertext_len)
+ const char *plaintext,
+ size_t plaintext_len,
+ char *ciphertext,
+ size_t *ciphertext_len)
{
return encrypt_update(ctx, (const unsigned char*)plaintext, plaintext_len,
- (unsigned char*)ciphertext, ciphertext_len, OP_SEAL);
+ (unsigned char*)ciphertext, ciphertext_len, OP_SEAL);
}
API int yaca_seal_finalize(yaca_context_h ctx,
- char *ciphertext,
- size_t *ciphertext_len)
+ char *ciphertext,
+ size_t *ciphertext_len)
{
return encrypt_finalize(ctx, (unsigned char*)ciphertext, ciphertext_len, OP_SEAL);
}
API int yaca_open_initialize(yaca_context_h *ctx,
- const yaca_key_h prv_key,
- yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t sym_key_bit_len,
- const yaca_key_h sym_key,
- const yaca_key_h iv)
+ const yaca_key_h prv_key,
+ yaca_encrypt_algorithm_e algo,
+ yaca_block_cipher_mode_e bcm,
+ size_t sym_key_bit_len,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv)
{
int ret;
const EVP_CIPHER *cipher;
yaca_key_h lsym_key = YACA_KEY_NULL;
if (prv_key == YACA_KEY_NULL || prv_key->type != YACA_KEY_TYPE_RSA_PRIV ||
- sym_key == YACA_KEY_NULL || bcm == YACA_BCM_WRAP || sym_key_bit_len % 8 != 0)
+ sym_key == YACA_KEY_NULL || bcm == YACA_BCM_WRAP || sym_key_bit_len % 8 != 0)
return YACA_ERROR_INVALID_PARAMETER;
ret = encrypt_get_algorithm(algo, bcm, sym_key_bit_len, &cipher);
}
API int yaca_open_update(yaca_context_h ctx,
- const char *ciphertext,
- size_t ciphertext_len,
- char *plaintext,
- size_t *plaintext_len)
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char *plaintext,
+ size_t *plaintext_len)
{
return encrypt_update(ctx, (const unsigned char*)ciphertext, ciphertext_len,
- (unsigned char*)plaintext, plaintext_len, OP_OPEN);
+ (unsigned char*)plaintext, plaintext_len, OP_OPEN);
}
API int yaca_open_finalize(yaca_context_h ctx,
- char *plaintext,
- size_t *plaintext_len)
+ char *plaintext,
+ size_t *plaintext_len)
{
return encrypt_finalize(ctx, (unsigned char*)plaintext, plaintext_len, OP_OPEN);
}
}
static int get_sign_output_length(const yaca_context_h ctx,
- size_t input_len,
- size_t *output_len)
+ size_t input_len,
+ size_t *output_len)
{
assert(output_len != NULL);
}
int set_sign_property(yaca_context_h ctx,
- yaca_property_e property,
- const void *value,
- size_t value_len)
+ yaca_property_e property,
+ const void *value,
+ size_t value_len)
{
int ret;
struct yaca_sign_context_s *c = get_sign_context(ctx);
}
API int yaca_sign_initialize(yaca_context_h *ctx,
- yaca_digest_algorithm_e algo,
- const yaca_key_h prv_key)
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h prv_key)
{
struct yaca_sign_context_s *nc = NULL;
const EVP_MD *md = NULL;
switch (prv_key->type) {
case YACA_KEY_TYPE_RSA_PRIV:
if (EVP_MD_size(md) >= EVP_PKEY_size(evp_key->evp) ||
- (algo == YACA_DIGEST_SHA384 && (EVP_PKEY_size(evp_key->evp) <= YACA_KEY_LENGTH_512BIT / 8)))
+ (algo == YACA_DIGEST_SHA384 && (EVP_PKEY_size(evp_key->evp) <= YACA_KEY_LENGTH_512BIT / 8)))
return YACA_ERROR_INVALID_PARAMETER;
break;
case YACA_KEY_TYPE_DSA_PRIV:
}
API int yaca_sign_initialize_hmac(yaca_context_h *ctx,
- yaca_digest_algorithm_e algo,
- const yaca_key_h sym_key)
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h sym_key)
{
struct yaca_sign_context_s *nc = NULL;
EVP_PKEY *pkey = NULL;
const struct yaca_key_simple_s *simple_key = key_get_simple(sym_key);
if (ctx == NULL || simple_key == NULL ||
- (sym_key->type != YACA_KEY_TYPE_SYMMETRIC && sym_key->type != YACA_KEY_TYPE_DES))
+ (sym_key->type != YACA_KEY_TYPE_SYMMETRIC && sym_key->type != YACA_KEY_TYPE_DES))
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_sign_context_s), (void**)&nc);
nc->ctx.get_property = NULL;
pkey = EVP_PKEY_new_mac_key(EVP_PKEY_HMAC,
- NULL,
- (unsigned char *)simple_key->d,
- simple_key->bit_len / 8);
+ NULL,
+ (unsigned char *)simple_key->d,
+ simple_key->bit_len / 8);
if (pkey == NULL) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
}
API int yaca_sign_initialize_cmac(yaca_context_h *ctx,
- yaca_encrypt_algorithm_e algo,
- const yaca_key_h sym_key)
+ yaca_encrypt_algorithm_e algo,
+ const yaca_key_h sym_key)
{
struct yaca_sign_context_s *nc = NULL;
CMAC_CTX* cmac_ctx = NULL;
const struct yaca_key_simple_s *simple_key = key_get_simple(sym_key);
if (ctx == NULL || simple_key == NULL ||
- (sym_key->type != YACA_KEY_TYPE_SYMMETRIC && sym_key->type != YACA_KEY_TYPE_DES))
+ (sym_key->type != YACA_KEY_TYPE_SYMMETRIC && sym_key->type != YACA_KEY_TYPE_DES))
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_zalloc(sizeof(struct yaca_sign_context_s), (void**)&nc);
}
API int yaca_sign_update(yaca_context_h ctx,
- const char *message,
- size_t message_len)
+ const char *message,
+ size_t message_len)
{
struct yaca_sign_context_s *c = get_sign_context(ctx);
int ret;
if (c == NULL || c->op_type != OP_SIGN ||
- message == NULL || message_len == 0)
+ message == NULL || message_len == 0)
return YACA_ERROR_INVALID_PARAMETER;
if (!verify_state_change(c, CTX_MSG_UPDATED))
}
API int yaca_sign_finalize(yaca_context_h ctx,
- char *signature,
- size_t *signature_len)
+ char *signature,
+ size_t *signature_len)
{
struct yaca_sign_context_s *c = get_sign_context(ctx);
int ret;
if (c == NULL || c->op_type != OP_SIGN ||
- signature == NULL || signature_len == NULL || *signature_len == 0)
+ signature == NULL || signature_len == NULL || *signature_len == 0)
return YACA_ERROR_INVALID_PARAMETER;
if (!verify_state_change(c, CTX_FINALIZED))
}
API int yaca_verify_initialize(yaca_context_h *ctx,
- yaca_digest_algorithm_e algo,
- const yaca_key_h pub_key)
+ yaca_digest_algorithm_e algo,
+ const yaca_key_h pub_key)
{
struct yaca_sign_context_s *nc = NULL;
const EVP_MD *md = NULL;
switch (pub_key->type) {
case YACA_KEY_TYPE_RSA_PUB:
if (EVP_MD_size(md) >= EVP_PKEY_size(evp_key->evp) ||
- (algo == YACA_DIGEST_SHA384 && (EVP_PKEY_size(evp_key->evp) <= YACA_KEY_LENGTH_512BIT / 8)))
+ (algo == YACA_DIGEST_SHA384 && (EVP_PKEY_size(evp_key->evp) <= YACA_KEY_LENGTH_512BIT / 8)))
return YACA_ERROR_INVALID_PARAMETER;
break;
case YACA_KEY_TYPE_DSA_PUB:
}
API int yaca_verify_update(yaca_context_h ctx,
- const char *message,
- size_t message_len)
+ const char *message,
+ size_t message_len)
{
struct yaca_sign_context_s *c = get_sign_context(ctx);
int ret;
}
API int yaca_verify_finalize(yaca_context_h ctx,
- const char *signature,
- size_t signature_len)
+ const char *signature,
+ size_t signature_len)
{
struct yaca_sign_context_s *c = get_sign_context(ctx);
int ret;
return YACA_ERROR_INVALID_PARAMETER;
ret = EVP_DigestVerifyFinal(c->md_ctx,
- (unsigned char *)signature,
- signature_len);
+ (unsigned char *)signature,
+ signature_len);
if (ret == 1) {
c->state = CTX_FINALIZED;
#include "internal.h"
API int yaca_simple_calculate_digest(yaca_digest_algorithm_e algo,
- const char *data,
- size_t data_len,
- char **digest,
- size_t *digest_len)
+ const char *data,
+ size_t data_len,
+ char **digest,
+ size_t *digest_len)
{
yaca_context_h ctx;
int ret;
size_t ldigest_len;
if ((data == NULL && data_len > 0) || (data != NULL && data_len == 0) ||
- digest == NULL || digest_len == NULL)
+ digest == NULL || digest_len == NULL)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_digest_initialize(&ctx, algo);
}
API int yaca_simple_encrypt(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *plaintext,
- size_t plaintext_len,
- char **ciphertext,
- size_t *ciphertext_len)
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *plaintext,
+ size_t plaintext_len,
+ char **ciphertext,
+ size_t *ciphertext_len)
{
yaca_context_h ctx;
int ret;
size_t written = 0;
if ((plaintext == NULL && plaintext_len > 0) || (plaintext != NULL && plaintext_len == 0) ||
- ciphertext == NULL || ciphertext_len == NULL ||
- sym_key == YACA_KEY_NULL ||
- bcm == YACA_BCM_CCM || bcm == YACA_BCM_GCM)
+ ciphertext == NULL || ciphertext_len == NULL ||
+ sym_key == YACA_KEY_NULL ||
+ bcm == YACA_BCM_CCM || bcm == YACA_BCM_GCM)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_encrypt_initialize(&ctx, algo, bcm, sym_key, iv);
assert(written <= lciphertext_len);
if (((bcm == YACA_BCM_CBC || bcm == YACA_BCM_ECB) && written == 0) ||
- (bcm != YACA_BCM_CBC && bcm != YACA_BCM_ECB && plaintext_len == 0 && written > 0)) {
+ (bcm != YACA_BCM_CBC && bcm != YACA_BCM_ECB && plaintext_len == 0 && written > 0)) {
ret = YACA_ERROR_INTERNAL;
goto exit;
}
}
API int yaca_simple_decrypt(yaca_encrypt_algorithm_e algo,
- yaca_block_cipher_mode_e bcm,
- const yaca_key_h sym_key,
- const yaca_key_h iv,
- const char *ciphertext,
- size_t ciphertext_len,
- char **plaintext,
- size_t *plaintext_len)
+ yaca_block_cipher_mode_e bcm,
+ const yaca_key_h sym_key,
+ const yaca_key_h iv,
+ const char *ciphertext,
+ size_t ciphertext_len,
+ char **plaintext,
+ size_t *plaintext_len)
{
yaca_context_h ctx;
int ret;
size_t written = 0;
if ((ciphertext == NULL && ciphertext_len > 0) || (ciphertext != NULL && ciphertext_len == 0) ||
- ((bcm == YACA_BCM_ECB || bcm == YACA_BCM_CBC) && ciphertext == NULL && ciphertext_len == 0) ||
- plaintext == NULL || plaintext_len == NULL ||
- sym_key == YACA_KEY_NULL ||
- bcm == YACA_BCM_CCM || bcm == YACA_BCM_GCM)
+ ((bcm == YACA_BCM_ECB || bcm == YACA_BCM_CBC) && ciphertext == NULL && ciphertext_len == 0) ||
+ plaintext == NULL || plaintext_len == NULL ||
+ sym_key == YACA_KEY_NULL ||
+ bcm == YACA_BCM_CCM || bcm == YACA_BCM_GCM)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_decrypt_initialize(&ctx, algo, bcm, sym_key, iv);
}
static int sign(const yaca_context_h ctx, const char *data, size_t data_len,
- char **signature, size_t *signature_len)
+ char **signature, size_t *signature_len)
{
int ret;
}
API int yaca_simple_calculate_signature(yaca_digest_algorithm_e algo,
- const yaca_key_h prv_key,
- const char *data,
- size_t data_len,
- char **signature,
- size_t *signature_len)
+ const yaca_key_h prv_key,
+ const char *data,
+ size_t data_len,
+ char **signature,
+ size_t *signature_len)
{
int ret;
yaca_context_h ctx = YACA_CONTEXT_NULL;
if ((data == NULL && data_len > 0) || (data != NULL && data_len == 0) ||
- signature == NULL || signature_len == NULL)
+ signature == NULL || signature_len == NULL)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_sign_initialize(&ctx, algo, prv_key);
}
API int yaca_simple_verify_signature(yaca_digest_algorithm_e algo,
- const yaca_key_h pub_key,
- const char *data,
- size_t data_len,
- const char *signature,
- size_t signature_len)
+ const yaca_key_h pub_key,
+ const char *data,
+ size_t data_len,
+ const char *signature,
+ size_t signature_len)
{
int ret;
yaca_context_h ctx = YACA_CONTEXT_NULL;
if ((data == NULL && data_len > 0) || (data != NULL && data_len == 0) ||
- signature == NULL || signature_len == 0)
+ signature == NULL || signature_len == 0)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_verify_initialize(&ctx, algo, pub_key);
}
API int yaca_simple_calculate_hmac(yaca_digest_algorithm_e algo,
- const yaca_key_h sym_key,
- const char *data,
- size_t data_len,
- char **mac,
- size_t *mac_len)
+ const yaca_key_h sym_key,
+ const char *data,
+ size_t data_len,
+ char **mac,
+ size_t *mac_len)
{
int ret;
yaca_context_h ctx = YACA_CONTEXT_NULL;
if ((data == NULL && data_len > 0) || (data != NULL && data_len == 0) ||
- mac == NULL || mac_len == NULL)
+ mac == NULL || mac_len == NULL)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_sign_initialize_hmac(&ctx, algo, sym_key);
}
API int yaca_simple_calculate_cmac(yaca_encrypt_algorithm_e algo,
- const yaca_key_h sym_key,
- const char *data,
- size_t data_len,
- char **mac,
- size_t *mac_len)
+ const yaca_key_h sym_key,
+ const char *data,
+ size_t data_len,
+ char **mac,
+ size_t *mac_len)
{
int ret;
yaca_context_h ctx = YACA_CONTEXT_NULL;
if ((data == NULL && data_len > 0) || (data != NULL && data_len == 0) ||
- mac == NULL || mac_len == NULL)
+ mac == NULL || mac_len == NULL)
return YACA_ERROR_INVALID_PARAMETER;
ret = yaca_sign_initialize_cmac(&ctx, algo, sym_key);