Fix checking input params for get_iv_length 60/231160/5
authorLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 17 Apr 2020 15:56:25 +0000 (17:56 +0200)
committerLukasz Pawelczyk <l.pawelczyk@samsung.com>
Fri, 26 Jun 2020 15:36:20 +0000 (17:36 +0200)
Without this change it was possible to trigger an assert using top
level API.

Unify wording for key_bit_len param "divisible by 8".

Change-Id: Iba4a121c38ce3dc78a7531a1df984c014edf84da

api/yaca/yaca_encrypt.h
api/yaca/yaca_key.h
src/encrypt.c

index ba2de37326e2fe719f4a7a901a66e892963f8a9d..bb307f4a646b366e21b543a1394ceadb7bb8fb9b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
  *
@@ -55,7 +55,8 @@ extern "C" {
  *         negative on error
  * @retval #YACA_ERROR_NONE Successful
  * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL,
- *                                       invalid @a algo, @a bcm or @a key_bit_len)
+ *                                       invalid @a algo, @a bcm or @a key_bit_len not
+ *                                       divisible by 8)
  * @retval #YACA_ERROR_INTERNAL Internal error
  */
 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);
index 4f82cd9dc91db7e88cfd030172aa10b230f1d70d..7ac0642d0b7f24099606f1cc0868a686bee8da55 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
  *
@@ -199,7 +199,7 @@ int yaca_key_export(const yaca_key_h key, yaca_key_format_e key_fmt, yaca_key_fi
  *         negative on error
  * @retval #YACA_ERROR_NONE Successful
  * @retval #YACA_ERROR_INVALID_PARAMETER @a key is NULL, incorrect @a key_type or
- *                                       @a key_bit_len is not dividable by 8
+ *                                       @a key_bit_len is not divisible by 8
  * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
  * @retval #YACA_ERROR_INTERNAL Internal error
  * @see #yaca_key_type_e
@@ -349,7 +349,7 @@ int yaca_key_derive_kdf(yaca_kdf_e kdf, yaca_digest_algorithm_e algo, const char
  *         negative on error
  * @retval #YACA_ERROR_NONE Successful
  * @retval #YACA_ERROR_INVALID_PARAMETER Required parameters have incorrect values (NULL, 0,
- *                                       invalid @a algo or @a key_bit_len not dividable by 8)
+ *                                       invalid @a algo or @a key_bit_len not divisible by 8)
  * @retval #YACA_ERROR_OUT_OF_MEMORY Out of memory error
  * @retval #YACA_ERROR_INTERNAL Internal error
  * @see #yaca_digest_algorithm_e
index 1fd935c8ca4c8e3f986a3bbe00badf38066a48f9..c413ea0466629306415c2c8bf26d0bc284292846 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
+ *  Copyright (c) 2016-2020 Samsung Electronics Co., Ltd All Rights Reserved
  *
  *  Contact: Krzysztof Jackiewicz <k.jackiewicz@samsung.com>
  *
@@ -1109,7 +1109,7 @@ API int yaca_encrypt_get_iv_bit_length(yaca_encrypt_algorithm_e algo,
        const EVP_CIPHER *cipher;
        int ret;
 
-       if (iv_bit_len == NULL)
+       if (iv_bit_len == NULL || key_bit_len % 8 != 0)
                return YACA_ERROR_INVALID_PARAMETER;
 
        ret = encrypt_get_algorithm(algo, bcm, key_bit_len, &cipher);