Return the value by size_t param instead of signed int return.
The return value is used only for error codes from now on.
Change-Id: I90afedcffeb37ab315b4f4681323f3d64b7bc9ec
/**
* @brief Returns the recomended/default length of the IV for a given encryption configuration.
*
- * @param[in] algo Encryption algorithm.
- * @param[in] bcm Chain mode.
- * @param[in] key_bits Key length in bits.
+ * If returned iv_bits equals 0 that means that for this
+ * specific algorithm and its parameters IV is not used.
*
- * @return negative on error or the IV length in bits.
+ * @param[in] algo Encryption algorithm.
+ * @param[in] bcm Chain mode.
+ * @param[in] key_bits Key length in bits.
+ * @param[out] iv_bits Recommended IV length in bits.
+ *
+ * @return 0 on success, negative on error.
*/
int yaca_get_iv_bits(yaca_enc_algo_e algo,
yaca_block_cipher_mode_e bcm,
- size_t key_bits);
+ size_t key_bits,
+ size_t *iv_bits);
/**@}*/
char *dec_data = NULL;
size_t enc_len;
size_t dec_len;
- int iv_bits;
+ size_t iv_bits;
printf("Simple Encrypt\nPlain data (16 of %zu bytes): %.16s\n",
LOREM1024_SIZE, lorem1024);
if (ret)
return;
- iv_bits = yaca_get_iv_bits(algo, bcm, key_bits);
- if (iv_bits < 0)
+ if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != 0)
return;
if (iv_bits > 0) {
char *dec = NULL;
size_t enc_size;
size_t dec_size;
- int iv_bits;
+ size_t iv_bits;
printf("Advanced Encrypt\nPlain data (16 of %zu bytes): %.16s\n",
LOREM4096_SIZE, lorem4096);
if (ret)
return;
- iv_bits = yaca_get_iv_bits(algo, bcm, key_bits);
- if (iv_bits < 0)
+ if (yaca_get_iv_bits(algo, bcm, key_bits, &iv_bits) != 0)
goto ex_key;
if (iv_bits > 0) {
}
API int yaca_get_iv_bits(yaca_enc_algo_e algo,
- yaca_block_cipher_mode_e bcm,
- size_t key_bits)
+ yaca_block_cipher_mode_e bcm,
+ size_t key_bits,
+ size_t *iv_bits)
{
const EVP_CIPHER *cipher;
int ret;
if (ret < 0)
return ret;
- return EVP_CIPHER_iv_length(cipher) * 8;
+ ret = EVP_CIPHER_iv_length(cipher);
+ if (ret < 0) {
+ ERROR_DUMP(YACA_ERROR_INTERNAL);
+ return YACA_ERROR_INTERNAL;
+ }
+
+ *iv_bits = ret * 8;
+ return 0;
}
API int yaca_encrypt_init(yaca_ctx_h *ctx,