Implement yaca_get_iv_bits() 00/65600/6
authorMateusz Kulikowski <m.kulikowski@samsung.com>
Mon, 11 Apr 2016 13:33:39 +0000 (15:33 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Thu, 14 Apr 2016 15:05:25 +0000 (17:05 +0200)
Move code to encrypt* as it's encryption related.

Change-Id: Id9b5072e3fb220aaffcc0f1aad5f2b0893fa06ed
Signed-off-by: Mateusz Kulikowski <m.kulikowski@samsung.com>
api/yaca/crypto.h
api/yaca/encrypt.h
src/crypto.c
src/encrypt.c

index 1b9feab..cd30ff2 100644 (file)
@@ -162,19 +162,6 @@ int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len);
  */
 #define yaca_get_block_length(ctxa) yaca_get_output_length((ctxa), 0)
 
-/**
- * @brief yaca_get_iv_bits  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 (@see crypto_key_len_e).
- *
- * @return negative on error (@see error.h) or the IV length in bits.
- */
-int yaca_get_iv_bits(yaca_enc_algo_e algo,
-                    yaca_block_cipher_mode_e bcm,
-                    size_t key_bits);
-
 /**@}*/
 
 #ifdef __cplusplus
index 38e565f..e94fb37 100644 (file)
@@ -247,6 +247,19 @@ int yaca_open_final(yaca_ctx_h ctx,
                    char *plain,
                    size_t *plain_len);
 
+/**
+ * @brief yaca_get_iv_bits  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 (@see crypto_key_len_e).
+ *
+ * @return negative on error (@see error.h) or the IV length in bits.
+ */
+int yaca_get_iv_bits(yaca_enc_algo_e algo,
+                    yaca_block_cipher_mode_e bcm,
+                    size_t key_bits);
+
 /**@}*/
 
 #ifdef __cplusplus
index 9081bcf..4a49071 100644 (file)
@@ -107,10 +107,3 @@ API int yaca_get_output_length(const yaca_ctx_h ctx, size_t input_len)
 
        return ctx->get_output_length(ctx, input_len);
 }
-
-API int yaca_get_iv_bits(yaca_enc_algo_e algo,
-                        yaca_block_cipher_mode_e bcm,
-                        size_t key_bits)
-{
-       return YACA_ERROR_NOT_IMPLEMENTED;
-}
index 596a1a4..bfd730d 100644 (file)
@@ -104,6 +104,20 @@ int get_symmetric_algorithm(yaca_enc_algo_e algo,
        return 0;
 }
 
+API int yaca_get_iv_bits(yaca_enc_algo_e algo,
+                        yaca_block_cipher_mode_e bcm,
+                        size_t key_bits)
+{
+       const EVP_CIPHER *cipher;
+       int ret;
+
+       ret = get_symmetric_algorithm(algo, bcm, key_bits, &cipher);
+       if (ret < 0)
+               return ret;
+
+       return EVP_CIPHER_iv_length(cipher) * 8;
+}
+
 API int yaca_encrypt_init(yaca_ctx_h *ctx,
                          yaca_enc_algo_e algo,
                          yaca_block_cipher_mode_e bcm,