*
* @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);
* @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);
* @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,
* @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,
* @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);
* @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);
* @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);
* 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);
* @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,
* 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,
* 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,
* @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,
* 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,
* 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,
* @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,
* @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);
* @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);
* @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()
*/
* (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,
* @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,
* @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);
* @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,
* @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,
* @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,
* @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,
* 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,
* 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,
* @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,
* 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,
* 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,
* - #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()
* - #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()
*/
* - #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()
*/
* @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()
*/
* @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()
*/
* - #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()
*/
* @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,
* @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()
*/
* (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,
* (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,
* (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,
* 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,
* @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(),
*/
* 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,
* 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,
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: ");
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: ");
yaca_debug_set_error_cb(debug_func);
int ret = yaca_init();
- if (ret != 0)
+ if (ret != YACA_ERROR_NONE)
return ret;
digest_simple();
/* 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);
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 */
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;
/* 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 */
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;
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;
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)
/* 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 */
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);
/* 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 */
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;
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)
/* 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 */
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);
/* 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 */
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;
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();
// 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
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:
// 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
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:
yaca_debug_set_error_cb(debug_func);
int ret = yaca_init();
- if (ret != 0)
+ if (ret != YACA_ERROR_NONE)
return ret;
key_exchange_dh();
/* 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);
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);
/* 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: *****");
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);
/* 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);
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);
/* 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);
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);
/* 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);
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);
/* 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);
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);
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");
}
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);
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");
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");
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");
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");
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);
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);
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);
yaca_exit();
- return 0;
+ return YACA_ERROR_NONE;
}
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 */
/* 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;
/* 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 */
/* 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;
yaca_debug_set_error_cb(debug_func);
int ret = yaca_init();
- if (ret != 0)
+ if (ret != YACA_ERROR_NONE)
return ret;
encrypt_seal();
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
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);
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);
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
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:");
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");
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:");
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");
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);
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);
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:");
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");
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)
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)
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");
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");
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;
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)
return ret;
}
- return 0;
+ return YACA_ERROR_NONE;
}
API int yaca_ctx_set_param(yaca_ctx_h ctx, yaca_ex_param_e param,
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;
}
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)
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;
break;
}
- if (ret == 0 && *md == NULL) {
+ if (ret == YACA_ERROR_NONE && *md == NULL) {
ret = YACA_ERROR_INTERNAL;
ERROR_DUMP(ret);
}
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();
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
ctx:
EVP_MD_CTX_destroy(nc->mdctx);
return ret;
}
- return 0;
+ return YACA_ERROR_NONE;
}
API int yaca_digest_final(yaca_ctx_h ctx, char *digest, size_t *digest_len)
*digest_len = len;
- return 0;
+ return YACA_ERROR_NONE;
}
*output_len = block_size;
}
- return 0;
+ return YACA_ERROR_NONE;
}
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,
return YACA_ERROR_INVALID_ARGUMENT;
break;
}
- return 0;
+ return YACA_ERROR_NONE;
}
static const char *encrypt_algo_to_str(yaca_enc_algo_e algo)
}
*cipher = lcipher;
- return 0;
+ return YACA_ERROR_NONE;
}
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);
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;
}
}
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
err_ctx:
EVP_CIPHER_CTX_free(nc->cipher_ctx);
}
*output_len = loutput_len;
- return 0;
+ return YACA_ERROR_NONE;
}
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,
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);
}
*iv_bits = ret * 8;
- return 0;
+ return YACA_ERROR_NONE;
}
API int yaca_encrypt_init(yaca_ctx_h *ctx,
}
*len = data_len / 4 * 3 - padded;
- return 0;
+ return YACA_ERROR_NONE;
}
#define TMP_BUF_LEN 512
/* 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());
goto free_bio;
}
- if (ret == 0)
+ if (ret == YACA_ERROR_NONE)
break;
if (BIO_write(dst, tmpbuf, ret) != ret) {
*output = dst;
dst = NULL;
- ret = 0;
+ ret = YACA_ERROR_NONE;
free_bio:
BIO_free_all(b64);
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) {
nk->key.type = key_type;
*key = (yaca_key_h)nk;
- ret = 0;
+ ret = YACA_ERROR_NONE;
out:
BIO_free_all(decoded);
(*key)->type = type;
pkey = NULL;
- ret = 0;
+ ret = YACA_ERROR_NONE;
free:
EVP_PKEY_free(pkey);
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,
memcpy(*data, bio_data, bio_data_len);
*data_len = bio_data_len;
- ret = 0;
+ ret = YACA_ERROR_NONE;
free_bio:
BIO_free_all(b64);
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;
memcpy(*data, bio_data, bio_data_len);
*data_len = bio_data_len;
- ret = 0;
+ ret = YACA_ERROR_NONE;
free_bio:
BIO_free_all(mem);
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)
nk->bits = key_bits;
*out = nk;
- return 0;
+ return YACA_ERROR_NONE;
free_nk:
yaca_free(nk);
*out = nk;
nk = NULL;
- ret = 0;
+ ret = YACA_ERROR_NONE;
free_ctx:
EVP_PKEY_CTX_free(ctx);
*out = nk;
nk = NULL;
- ret = 0;
+ ret = YACA_ERROR_NONE;
free_kctx:
EVP_PKEY_CTX_free(kctx);
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)
if (simple_key != NULL) {
*key_bits = simple_key->bits;
- return 0;
+ return YACA_ERROR_NONE;
}
if (evp_key != NULL) {
}
*key_bits = ret;
- return 0;
+ return YACA_ERROR_NONE;
}
return YACA_ERROR_INVALID_ARGUMENT;
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:
goto free_pkey;
}
- return 0;
+ return YACA_ERROR_NONE;
free_pkey:
EVP_PKEY_free(pkey);
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);
}
*key = (yaca_key_h)nk;
- return 0;
+ return YACA_ERROR_NONE;
err:
yaca_free(nk);
return ret;
*output_len = block_size;
}
- return 0;
+ return YACA_ERROR_NONE;
}
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);
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
err_iv:
yaca_free(liv);
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);
// 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;
}
}
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
err_ctx:
EVP_CIPHER_CTX_free(nc->cipher_ctx);
return ret;
}
- return 0;
+ return YACA_ERROR_NONE;
}
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,
}
*output_len = len;
- return 0;
+ return YACA_ERROR_NONE;
}
static void destroy_sign_context(yaca_ctx_h ctx)
return ret;
}
- return 0;
+ return YACA_ERROR_NONE;
}
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,
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();
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
free_ctx:
yaca_ctx_free((yaca_ctx_h)nc);
}
ret = digest_get_algorithm(algo, &md);
- if (ret != 0)
+ if (ret != YACA_ERROR_NONE)
goto free_pkey;
nc->mdctx = EVP_MD_CTX_create();
}
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
free_pkey:
EVP_PKEY_free(pkey);
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;
}
// 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);
return ret;
}
- return 0;
+ return YACA_ERROR_NONE;
}
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,
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();
*ctx = (yaca_ctx_h)nc;
- return 0;
+ return YACA_ERROR_NONE;
free_ctx:
yaca_ctx_free((yaca_ctx_h)nc);
return ret;
}
- return 0;
+ return YACA_ERROR_NONE;
}
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;
}
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);
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);
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) {
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);
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;
*cipher = rcipher;
*cipher_len = written;
- return 0;
+ return YACA_ERROR_NONE;
err_free:
yaca_free(lcipher);
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) {
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);
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;
*plain = rplain;
*plain_len = written;
- return 0;
+ return YACA_ERROR_NONE;
err_free:
yaca_free(lplain);
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);
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;
}
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);
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);
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);
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);