Skip to content

Commit 94b5f0f

Browse files
committed
tests: Crypto: IS_ENABLED
1 parent 8c02821 commit 94b5f0f

File tree

2 files changed

+19
-17
lines changed

2 files changed

+19
-17
lines changed

tests/crypto/psa_crypto/src/cipher.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <zephyr/ztest.h>
88
#include <psa/crypto.h>
9+
#include <zephyr/sys/util_macro.h>
910

1011
#include "test_vectors.h"
1112

@@ -40,15 +41,15 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_multipart)
4041
psa_set_key_algorithm(&attributes, alg);
4142
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
4243
psa_set_key_bits(&attributes, 256);
43-
#if (CONFIG_TEST_WRAPPED_KEYS)
44+
if(IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
4445
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
4546
PSA_KEY_PERSISTENCE_VOLATILE, 0));
4647
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
4748
"Failed to generate key");
48-
# else
49+
} else {
4950
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
5051
PSA_SUCCESS, "Failed to import key");
51-
#endif
52+
}
5253
psa_reset_key_attributes(&attributes);
5354
zassert_equal(psa_cipher_encrypt_setup(&operation, key_id, alg), PSA_SUCCESS,
5455
"Failed to begin encrypt operation");
@@ -95,15 +96,15 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_single)
9596
psa_set_key_algorithm(&attributes, alg);
9697
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
9798
psa_set_key_bits(&attributes, 256);
98-
#if (CONFIG_TEST_WRAPPED_KEYS)
99+
if(IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
99100
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
100101
PSA_KEY_PERSISTENCE_VOLATILE, 1));
101102
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
102103
"Failed to generate key");
103-
# else
104+
} else {
104105
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
105106
PSA_SUCCESS, "Failed to import key");
106-
#endif
107+
}
107108
psa_reset_key_attributes(&attributes);
108109

109110
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext),
@@ -133,16 +134,16 @@ ZTEST(psa_crypto_test, test_cipher_aes_ecb_128_single)
133134
psa_set_key_algorithm(&attributes, alg);
134135
psa_set_key_type(&attributes, PSA_KEY_TYPE_AES);
135136
psa_set_key_bits(&attributes, 128);
136-
#if (CONFIG_TEST_WRAPPED_KEYS)
137+
if(IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
137138
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
138139
PSA_KEY_PERSISTENCE_VOLATILE, 1));
139140

140141
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
141142
"Failed to generate key");
142-
# else
143+
} else {
143144
zassert_equal(psa_import_key(&attributes, key_128, sizeof(key_128), &key_id),
144145
PSA_SUCCESS, "Failed to import key");
145-
#endif
146+
}
146147
psa_reset_key_attributes(&attributes);
147148

148149
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext), ciphertext,

tests/crypto/psa_crypto/src/key_agreement.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
#include <zephyr/ztest.h>
88
#include <psa/crypto.h>
9+
#include <zephyr/sys/util_macro.h>
910

1011
static const uint8_t client_private_key[] = {
1112
0xB0, 0x76, 0x51, 0xEA, 0x20, 0xF0, 0x28, 0xA8, 0x16, 0xEE, 0x01,
@@ -27,13 +28,13 @@ static const uint8_t server_public_key[] = {
2728
0x8D, 0x49, 0x85, 0x8C, 0x7A, 0x9F, 0xC1, 0x46, 0xDA, 0xCC, 0x96,
2829
0xEF, 0x6E, 0xD4, 0xDA, 0x71, 0xBF, 0xED, 0x32, 0x0D, 0x76,
2930
};
30-
#if (!CONFIG_TEST_WRAPPED_KEYS)
31+
if(!IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
3132
static const uint8_t expected_shared_secret[] = {
3233
0xF2, 0xE6, 0x0E, 0x1C, 0xB7, 0x64, 0xBC, 0x48, 0xF2, 0x9D, 0xBB,
3334
0x12, 0xFB, 0x12, 0x17, 0x31, 0x32, 0x1D, 0x79, 0xAF, 0x0A, 0x9F,
3435
0xAB, 0xAD, 0x34, 0x05, 0xA2, 0x07, 0x39, 0x9C, 0x5F, 0x15,
3536
};
36-
#endif
37+
}
3738
ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
3839
{
3940
uint8_t shared_secret_buf[32];
@@ -45,10 +46,10 @@ ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
4546
psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_MONTGOMERY));
4647
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
4748
psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
48-
#if (CONFIG_TEST_WRAPPED_KEYS)
49+
if(IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
4950
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
5051
PSA_KEY_PERSISTENCE_VOLATILE, 0));
51-
#endif
52+
}
5253
zassert_equal(psa_import_key(&attributes, client_private_key, sizeof(client_private_key),
5354
&key_id),
5455
PSA_SUCCESS, "Failed to import client key");
@@ -66,10 +67,10 @@ ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
6667
psa_set_key_type(&attributes, PSA_KEY_TYPE_ECC_KEY_PAIR(PSA_ECC_FAMILY_MONTGOMERY));
6768
psa_set_key_usage_flags(&attributes, PSA_KEY_USAGE_DERIVE);
6869
psa_set_key_algorithm(&attributes, PSA_ALG_ECDH);
69-
#if (CONFIG_TEST_WRAPPED_KEYS)
70+
if(IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
7071
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
7172
PSA_KEY_PERSISTENCE_VOLATILE, 0));
72-
#endif
73+
}
7374
zassert_equal(psa_import_key(&attributes, server_private_key, sizeof(server_private_key),
7475
&key_id),
7576
PSA_SUCCESS, "Failed to import server key");
@@ -81,10 +82,10 @@ ZTEST(psa_crypto_test, test_key_agreement_ecdh_25519)
8182
PSA_SUCCESS, "Failed to perform key agreement with client");
8283

8384
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy server key");
84-
#if (!CONFIG_TEST_WRAPPED_KEYS)
85+
if(!IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
8586
/* Verify shared secret */
8687
zassert_mem_equal(shared_secret_buf, expected_shared_secret,
8788
sizeof(expected_shared_secret),
8889
"Key agreement did not resolve the correct shared secret");
89-
#endif
90+
}
9091
}

0 commit comments

Comments
 (0)