/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
*
part = left;
}
}
+
+void decrypt_check(int ret, size_t actual_len, size_t expected_len)
+{
+ if (ret != YACA_ERROR_INVALID_PARAMETER) {
+ BOOST_REQUIRE(ret == YACA_ERROR_NONE);
+ BOOST_REQUIRE(actual_len != expected_len);
+ }
+}
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
*
}
}
+/*
+ * There's a quite high (over 1/256) chance that the decryption with wrong key, bcm, iv or
+ * ciphertext will create a correctly padded buffer (e.g. last byte equal to 0x01). In such case we
+ * expect that the length of the decrypted buffer will not match the original one.
+ */
+void decrypt_check(int ret, size_t actual_len, size_t expected_len);
#endif /* COMMON_H */
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
*
decrypted_len = written;
ret = yaca_decrypt_finalize(ctx, decrypted + decrypted_len, &written);
- BOOST_REQUIRE(ret == YACA_ERROR_INVALID_PARAMETER);
+ decrypt_check(ret, decrypted_len + written, INPUT_DATA_SIZE);
yaca_context_destroy(ctx);
ctx = YACA_CONTEXT_NULL;
decrypted_len = written;
ret = yaca_decrypt_finalize(ctx, decrypted + decrypted_len, &written);
- if (ret != YACA_ERROR_INVALID_PARAMETER) {
- /*
- * There's a quite high (over 1/256) chance that the decryption with key2 will create
- * a correctly padded buffer (e.g. last byte equal to 0x01). In such case we expect that
- * the length of the decrypted buffer will not match the original one.
- */
-
- BOOST_REQUIRE(ret == YACA_ERROR_NONE);
- BOOST_REQUIRE(decrypted_len + written != INPUT_DATA_SIZE);
- }
+ decrypt_check(ret, decrypted_len + written, INPUT_DATA_SIZE);
yaca_context_destroy(ctx);
ctx = YACA_CONTEXT_NULL;
decrypted_len = written;
ret = yaca_decrypt_finalize(ctx, decrypted + decrypted_len, &written);
- BOOST_REQUIRE(ret == YACA_ERROR_INVALID_PARAMETER);
+ decrypt_check(ret, decrypted_len + written, INPUT_DATA_SIZE);
yaca_context_destroy(ctx);
ctx = YACA_CONTEXT_NULL;
/*
- * Copyright (c) 2020 Samsung Electronics Co., Ltd All Rights Reserved
+ * Copyright (c) 2020 - 2021 Samsung Electronics Co., Ltd All Rights Reserved
*
* Contact: Lukasz Pawelczyk <l.pawelczyk@samsung.com>
*
ret = yaca_simple_decrypt(YACA_ENCRYPT_AES, YACA_BCM_CBC, sym2, iv,
encrypted, encrypted_len,
&decrypted, &decrypted_len);
- BOOST_REQUIRE(ret == YACA_ERROR_INVALID_PARAMETER);
+ decrypt_check(ret, decrypted_len, INPUT_DATA_SIZE);
ret = yaca_simple_decrypt(YACA_ENCRYPT_AES, YACA_BCM_CBC, sym, iv2,
encrypted, encrypted_len,
ret = yaca_simple_decrypt(YACA_ENCRYPT_AES, YACA_BCM_CBC, sym, iv,
encrypted, encrypted_len,
&decrypted, &decrypted_len);
- BOOST_REQUIRE(ret == YACA_ERROR_INVALID_PARAMETER);
+ decrypt_check(ret, decrypted_len, INPUT_DATA_SIZE);
yaca_key_destroy(sym);
yaca_key_destroy(sym2);