1 /*
2  * Copyright (c) 2022 Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include "mocks/aes.h"
8 #include "mocks/aes_expects.h"
9 
10 #include <zephyr/bluetooth/crypto.h>
11 #include <zephyr/fff.h>
12 #include <zephyr/kernel.h>
13 
14 #include <host/crypto.h>
15 
16 DEFINE_FFF_GLOBALS;
17 
fff_reset_rule_before(const struct ztest_unit_test * test,void * fixture)18 static void fff_reset_rule_before(const struct ztest_unit_test *test, void *fixture)
19 {
20 	AES_FFF_FAKES_LIST(RESET_FAKE);
21 }
22 
23 ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL);
24 
25 ZTEST_SUITE(bt_encrypt_be, NULL, NULL, NULL, NULL, NULL);
26 
27 /*
28  *  Test bt_encrypt_be() succeeds
29  *
30  *  Constraints:
31  *   - psa_import_key() succeeds and returns 'PSA_SUCCESS'.
32  *   - psa_cipher_encrypt() succeeds and returns 'PSA_SUCCESS'.
33  *
34  *  Expected behaviour:
35  *   - bt_encrypt_be() returns 0 (success)
36  */
ZTEST(bt_encrypt_be,test_bt_encrypt_be_succeeds)37 ZTEST(bt_encrypt_be, test_bt_encrypt_be_succeeds)
38 {
39 	int err;
40 	const uint8_t key[16] = {0};
41 	const uint8_t plaintext[16] = {0};
42 	uint8_t enc_data[16] = {0};
43 
44 	psa_import_key_fake.return_val = PSA_SUCCESS;
45 	psa_cipher_encrypt_fake.return_val = PSA_SUCCESS;
46 
47 	err = bt_encrypt_be(key, plaintext, enc_data);
48 
49 	expect_single_call_psa_cipher_encrypt(enc_data);
50 
51 	zassert_ok(err, "Unexpected error code '%d' was returned", err);
52 }
53