Skip to content

Commit 91ed709

Browse files
committed
intendation errors
1 parent ee71bcf commit 91ed709

File tree

5 files changed

+121
-123
lines changed

5 files changed

+121
-123
lines changed

tests/crypto/psa_crypto/src/aead.c

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
11
/*
2-
* Copyright (c) 2025 Silicon Laboratories Inc.
3-
*
4-
* SPDX-License-Identifier: Apache-2.0
5-
*/
2+
* Copyright (c) 2025 Silicon Laboratories Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
66

77
#include <zephyr/ztest.h>
88
#include <psa/crypto.h>
99

1010
const uint8_t aes_key_buf[] = {0xea, 0x4f, 0x6f, 0x3c, 0x2f, 0xed, 0x2b, 0x9d,
11-
0xd9, 0x70, 0x8c, 0x2e, 0x72, 0x1a, 0xe0, 0x0f};
11+
0xd9, 0x70, 0x8c, 0x2e, 0x72, 0x1a, 0xe0, 0x0f};
1212
const uint8_t aes_nonce_buf[] = {0xf9, 0x75, 0x80, 0x9d, 0xdb, 0x51,
13-
0x72, 0x38, 0x27, 0x45, 0x63, 0x4f};
13+
0x72, 0x38, 0x27, 0x45, 0x63, 0x4f};
1414
const uint8_t aes_ad_buf[] = {0x5c, 0x65, 0xd4, 0xf2, 0x61, 0xd2, 0xc5, 0x4f, 0xfe, 0x6a};
1515
const uint8_t aes_plaintext[] = {0x8d, 0x6c, 0x08, 0x44, 0x6c, 0xb1, 0x0d, 0x9a, 0x20, 0x75};
1616

1717
const uint8_t chachapoly_key_buf[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
18-
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
19-
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
20-
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f};
18+
0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
19+
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
20+
0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f};
2121
const uint8_t chachapoly_nonce_buf[] = {0x07, 0x00, 0x00, 0x00, 0x40, 0x41,
2222
0x42, 0x43, 0x44, 0x45, 0x46, 0x47};
2323
const uint8_t chachapoly_ad_buf[] = {0x50, 0x51, 0x52, 0x53, 0xc0, 0xc1,
24-
0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7};
24+
0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7};
2525
const uint8_t chachapoly_plaintext[] = {
2626
0x4c, 0x61, 0x64, 0x69, 0x65, 0x73, 0x20, 0x61, 0x6e, 0x64, 0x20, 0x47, 0x65, 0x6e, 0x74,
2727
0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x20, 0x6f, 0x66, 0x20, 0x74, 0x68, 0x65, 0x20, 0x63, 0x6c,
@@ -62,23 +62,25 @@ ZTEST(psa_crypto_test, test_aead_aes_ccm)
6262
psa_set_key_algorithm(&attributes, alg);
6363

6464
zassert_equal(psa_import_key(&attributes, aes_key_buf, sizeof(aes_key_buf), &key_id),
65-
PSA_SUCCESS, "Failed to import key");
65+
PSA_SUCCESS, "Failed to import key");
6666

6767
zassert_equal(psa_aead_encrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
68-
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
69-
sizeof(aes_plaintext), cipher_tag_buf,
70-
sizeof(cipher_tag_buf), &out_len),
71-
PSA_SUCCESS, "Failed to encrypt");
68+
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
69+
sizeof(aes_plaintext), cipher_tag_buf,
70+
sizeof(cipher_tag_buf), &out_len),
71+
PSA_SUCCESS, "Failed to encrypt");
7272

7373
zassert_equal(out_len, sizeof(expect_cipher_tag_buf));
7474
zassert_mem_equal(cipher_tag_buf, expect_cipher_tag_buf, sizeof(expect_cipher_tag_buf));
75+
7576
zassert_equal(psa_aead_decrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
76-
aes_ad_buf, sizeof(aes_ad_buf), cipher_tag_buf, out_len,
77-
decrypted, sizeof(decrypted), &out_len),
78-
PSA_SUCCESS, "Failed to decrypt");
77+
aes_ad_buf, sizeof(aes_ad_buf), cipher_tag_buf, out_len,
78+
decrypted, sizeof(decrypted), &out_len),
79+
PSA_SUCCESS, "Failed to decrypt");
7980

8081
zassert_equal(out_len, sizeof(aes_plaintext));
8182
zassert_mem_equal(decrypted, aes_plaintext, sizeof(aes_plaintext));
83+
8284
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy key");
8385
}
8486

@@ -101,21 +103,21 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
101103
psa_set_key_algorithm(&attributes, alg);
102104

103105
zassert_equal(psa_import_key(&attributes, aes_key_buf, sizeof(aes_key_buf), &key_id),
104-
PSA_SUCCESS, "Failed to import key");
106+
PSA_SUCCESS, "Failed to import key");
105107

106108
zassert_equal(psa_aead_encrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
107-
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
108-
sizeof(aes_plaintext), cipher_tag_buf,
109-
sizeof(cipher_tag_buf), &out_len),
110-
PSA_SUCCESS, "Failed to encrypt");
109+
aes_ad_buf, sizeof(aes_ad_buf), aes_plaintext,
110+
sizeof(aes_plaintext), cipher_tag_buf,
111+
sizeof(cipher_tag_buf), &out_len),
112+
PSA_SUCCESS, "Failed to encrypt");
111113

112114
zassert_equal(out_len, sizeof(expect_cipher_tag_buf));
113115
zassert_mem_equal(cipher_tag_buf, expect_cipher_tag_buf, sizeof(expect_cipher_tag_buf));
114116

115117
zassert_equal(psa_aead_decrypt(key_id, alg, aes_nonce_buf, sizeof(aes_nonce_buf),
116-
aes_ad_buf, sizeof(aes_ad_buf), cipher_tag_buf, out_len,
117-
decrypted, sizeof(decrypted), &out_len),
118-
PSA_SUCCESS, "Failed to decrypt");
118+
aes_ad_buf, sizeof(aes_ad_buf), cipher_tag_buf, out_len,
119+
decrypted, sizeof(decrypted), &out_len),
120+
PSA_SUCCESS, "Failed to decrypt");
119121

120122
zassert_equal(out_len, sizeof(aes_plaintext));
121123
zassert_mem_equal(decrypted, aes_plaintext, sizeof(aes_plaintext));
@@ -128,6 +130,7 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
128130
uint8_t cipher_tag_buf[130]; /* Ciphertext + Tag */
129131
uint8_t decrypted[sizeof(chachapoly_plaintext)] = {0};
130132
size_t out_len;
133+
131134
psa_key_id_t key_id;
132135
psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT;
133136
psa_algorithm_t alg = PSA_ALG_CHACHA20_POLY1305;
@@ -137,27 +140,28 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
137140
psa_set_key_algorithm(&attributes, alg);
138141

139142
zassert_equal(psa_import_key(&attributes, chachapoly_key_buf, sizeof(chachapoly_key_buf),
140-
&key_id),
141-
PSA_SUCCESS, "Failed to import key");
143+
&key_id),
144+
PSA_SUCCESS, "Failed to import key");
142145

143146
zassert_equal(psa_aead_encrypt(key_id, alg, chachapoly_nonce_buf,
144-
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
145-
sizeof(chachapoly_ad_buf), chachapoly_plaintext,
146-
sizeof(chachapoly_plaintext), cipher_tag_buf,
147-
sizeof(cipher_tag_buf), &out_len),
148-
PSA_SUCCESS, "Failed to encrypt");
147+
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
148+
sizeof(chachapoly_ad_buf), chachapoly_plaintext,
149+
sizeof(chachapoly_plaintext), cipher_tag_buf,
150+
sizeof(cipher_tag_buf), &out_len),
151+
PSA_SUCCESS, "Failed to encrypt");
149152

150153
zassert_equal(out_len, sizeof(chachapoly_expect_cipher_tag_buf));
151154
zassert_mem_equal(cipher_tag_buf, chachapoly_expect_cipher_tag_buf,
152-
sizeof(chachapoly_expect_cipher_tag_buf));
155+
sizeof(chachapoly_expect_cipher_tag_buf));
153156

154157
zassert_equal(psa_aead_decrypt(key_id, alg, chachapoly_nonce_buf,
155-
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
156-
sizeof(chachapoly_ad_buf), cipher_tag_buf, out_len,
157-
decrypted, sizeof(decrypted), &out_len),
158-
PSA_SUCCESS, "Failed to decrypt");
158+
sizeof(chachapoly_nonce_buf), chachapoly_ad_buf,
159+
sizeof(chachapoly_ad_buf), cipher_tag_buf, out_len,
160+
decrypted, sizeof(decrypted), &out_len),
161+
PSA_SUCCESS, "Failed to decrypt");
159162

160163
zassert_equal(out_len, sizeof(chachapoly_plaintext));
161164
zassert_mem_equal(decrypted, chachapoly_plaintext, sizeof(chachapoly_plaintext));
165+
162166
zassert_equal(psa_destroy_key(key_id), PSA_SUCCESS, "Failed to destroy key");
163-
}
167+
}

tests/crypto/psa_crypto/src/cipher.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2025 Silicon Laboratories Inc.
3-
*
4-
* SPDX-License-Identifier: Apache-2.0
5-
*/
2+
* Copyright (c) 2025 Silicon Laboratories Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
66

77
#include <zephyr/ztest.h>
88
#include <psa/crypto.h>
@@ -42,41 +42,42 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_multipart)
4242
psa_set_key_bits(&attributes, 256);
4343
if (IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
4444
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
45-
PSA_KEY_PERSISTENCE_VOLATILE, 0));
45+
PSA_KEY_PERSISTENCE_VOLATILE, 0));
4646
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
47-
"Failed to generate key");
47+
"Failed to generate key");
4848
} else {
4949
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
50-
PSA_SUCCESS, "Failed to import key");
50+
PSA_SUCCESS, "Failed to import key");
5151
}
5252
psa_reset_key_attributes(&attributes);
53+
5354
zassert_equal(psa_cipher_encrypt_setup(&operation, key_id, alg), PSA_SUCCESS,
54-
"Failed to begin encrypt operation");
55+
"Failed to begin encrypt operation");
5556
zassert_equal(psa_cipher_generate_iv(&operation, iv, sizeof(iv), &iv_len), PSA_SUCCESS,
56-
"Failed to generate IV");
57+
"Failed to generate IV");
5758
zassert_equal(psa_cipher_update(&operation, plaintext, sizeof(plaintext), ciphertext,
58-
sizeof(ciphertext), &ciphertext_len),
59-
PSA_SUCCESS, "Failed to update encrypt operation");
59+
sizeof(ciphertext), &ciphertext_len),
60+
PSA_SUCCESS, "Failed to update encrypt operation");
6061
zassert_equal(psa_cipher_finish(&operation, ciphertext + ciphertext_len,
61-
sizeof(ciphertext) - ciphertext_len, &ciphertext_len),
62-
PSA_SUCCESS, "Failed to finish encrypt operation");
62+
sizeof(ciphertext) - ciphertext_len, &ciphertext_len),
63+
PSA_SUCCESS, "Failed to finish encrypt operation");
6364

6465
psa_cipher_abort(&operation);
6566

6667
zassert(memcmp(ciphertext, plaintext, sizeof(plaintext)) != 0,
6768
"Ciphertext identical to plaintext");
6869

6970
zassert_equal(psa_cipher_decrypt_setup(&operation, key_id, alg), PSA_SUCCESS,
70-
"Failed to begin decrypt operation");
71+
"Failed to begin decrypt operation");
7172
zassert_equal(psa_cipher_set_iv(&operation, iv, sizeof(iv)), PSA_SUCCESS,
72-
"Failed to set IV");
73+
"Failed to set IV");
7374
zassert_equal(psa_cipher_update(&operation, ciphertext, sizeof(ciphertext), decrypted,
7475
sizeof(decrypted), &decrypted_len),
75-
PSA_SUCCESS, "Failed to update decrypt operation");
76+
PSA_SUCCESS, "Failed to update decrypt operation");
7677
zassert_equal(decrypted_len, sizeof(decrypted), "Decrypted length mismatch");
7778
zassert_equal(psa_cipher_finish(&operation, decrypted + decrypted_len,
7879
sizeof(decrypted) - decrypted_len, &decrypted_len),
79-
PSA_SUCCESS, "Failed to finish decrypt operation");
80+
PSA_SUCCESS, "Failed to finish decrypt operation");
8081

8182
psa_cipher_abort(&operation);
8283

@@ -97,26 +98,26 @@ ZTEST(psa_crypto_test, test_cipher_aes_cbc_256_single)
9798
psa_set_key_bits(&attributes, 256);
9899
if (IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
99100
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
100-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
101+
PSA_KEY_PERSISTENCE_VOLATILE, 0));
101102
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
102-
"Failed to generate key");
103+
"Failed to generate key");
103104
} else {
104105
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id),
105-
PSA_SUCCESS, "Failed to import key");
106+
PSA_SUCCESS, "Failed to import key");
106107
}
107108
psa_reset_key_attributes(&attributes);
108109

109110
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext),
110-
ciphertext_buffer_256, sizeof(ciphertext_buffer_256),
111-
&ciphertext_len),
112-
PSA_SUCCESS, "Failed to perform one-shot encrypt operation");
111+
ciphertext_buffer_256, sizeof(ciphertext_buffer_256),
112+
&ciphertext_len),
113+
PSA_SUCCESS, "Failed to perform one-shot encrypt operation");
113114

114115
zassert(memcmp(ciphertext_buffer_256, plaintext, sizeof(plaintext)) != 0,
115116
"Ciphertext identical to plaintext");
116117

117118
zassert_equal(psa_cipher_decrypt(key_id, alg, ciphertext_buffer_256, ciphertext_len,
118-
decrypted, sizeof(decrypted), &decrypted_len),
119-
PSA_SUCCESS, "Failed to perform one-shot decrypt operation");
119+
decrypted, sizeof(decrypted), &decrypted_len),
120+
PSA_SUCCESS, "Failed to perform one-shot decrypt operation");
120121

121122
zassert_equal(decrypted_len, sizeof(decrypted), "Decrypted length mismatch");
122123
zassert_mem_equal(decrypted, plaintext, sizeof(plaintext));
@@ -135,26 +136,26 @@ ZTEST(psa_crypto_test, test_cipher_aes_ecb_128_single)
135136
psa_set_key_bits(&attributes, 128);
136137
if (IS_ENABLED(CONFIG_TEST_WRAPPED_KEYS)) {
137138
psa_set_key_lifetime(&attributes, PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION(
138-
PSA_KEY_PERSISTENCE_VOLATILE, 1));
139+
PSA_KEY_PERSISTENCE_VOLATILE, 0));
139140

140141
zassert_equal(psa_generate_key(&attributes, &key_id), PSA_SUCCESS,
141-
"Failed to generate key");
142+
"Failed to generate key");
142143
} else {
143144
zassert_equal(psa_import_key(&attributes, key_128, sizeof(key_128), &key_id),
144-
PSA_SUCCESS, "Failed to import key");
145+
PSA_SUCCESS, "Failed to import key");
145146
}
146147
psa_reset_key_attributes(&attributes);
147148

148149
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext), ciphertext,
149150
sizeof(ciphertext), &ciphertext_len),
150-
PSA_SUCCESS, "Failed to perform one-shot encrypt operation");
151+
PSA_SUCCESS, "Failed to perform one-shot encrypt operation");
151152

152153
zassert(memcmp(ciphertext, plaintext, sizeof(plaintext)) != 0,
153154
"Ciphertext identical to plaintext");
154155

155156
zassert_equal(psa_cipher_decrypt(key_id, alg, ciphertext, ciphertext_len, decrypted,
156157
sizeof(decrypted), &decrypted_len),
157-
PSA_SUCCESS, "Failed to perform one-shot decrypt operation");
158+
PSA_SUCCESS, "Failed to perform one-shot decrypt operation");
158159
zassert_equal(decrypted_len, sizeof(decrypted), "Decrypted length mismatch");
159160
zassert_mem_equal(decrypted, plaintext, sizeof(plaintext));
160161

@@ -173,19 +174,19 @@ ZTEST(psa_crypto_test, test_cipher_chacha20_single)
173174
psa_set_key_algorithm(&attributes, alg);
174175

175176
zassert_equal(psa_import_key(&attributes, key_256, sizeof(key_256), &key_id), PSA_SUCCESS,
176-
"Failed to import key");
177+
"Failed to import key");
177178

178179
zassert_equal(psa_cipher_encrypt(key_id, alg, plaintext, sizeof(plaintext),
179180
ciphertext_buffer_256, sizeof(ciphertext_buffer_256),
180181
&out_len),
181-
PSA_SUCCESS, "Failed to encrypt");
182+
PSA_SUCCESS, "Failed to encrypt");
182183

183184
zassert(memcmp(ciphertext_buffer_256, plaintext, sizeof(plaintext)) != 0,
184185
"Ciphertext identical to plaintext");
185186

186187
zassert_equal(psa_cipher_decrypt(key_id, alg, ciphertext_buffer_256, out_len, decrypted,
187188
sizeof(decrypted), &out_len),
188-
PSA_SUCCESS, "Failed to decrypt");
189+
PSA_SUCCESS, "Failed to decrypt");
189190

190191
zassert_mem_equal(decrypted, plaintext, sizeof(plaintext));
191-
}
192+
}

tests/crypto/psa_crypto/src/hash.c

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/*
2-
* Copyright (c) 2025 Silicon Laboratories Inc.
3-
*
4-
* SPDX-License-Identifier: Apache-2.0
5-
*/
2+
* Copyright (c) 2025 Silicon Laboratories Inc.
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
66

77
#include <zephyr/ztest.h>
88
#include <psa/crypto.h>
@@ -21,16 +21,15 @@ ZTEST(psa_crypto_test, test_hash_sha256)
2121
size_t hash_len;
2222

2323
zassert_equal(psa_hash_compute(PSA_ALG_SHA_256, plaintext, sizeof(plaintext), hash_buf,
24-
sizeof(hash_buf), &hash_len),
25-
PSA_SUCCESS, "Failed to perform hash");
26-
24+
sizeof(hash_buf), &hash_len),
25+
PSA_SUCCESS, "Failed to compute hash");
2726
zassert_equal(hash_len, sizeof(expect_sha256_hash), "Hash length mismatch");
2827
zassert_mem_equal(hash_buf, expect_sha256_hash, sizeof(expect_sha256_hash),
29-
"Hash mismatch");
28+
"Hash mismatch");
3029

3130
zassert_equal(psa_hash_compare(PSA_ALG_SHA_256, plaintext, sizeof(plaintext),
32-
expect_sha256_hash, sizeof(expect_sha256_hash)),
33-
PSA_SUCCESS, "Failed to compare hash");
31+
expect_sha256_hash, sizeof(expect_sha256_hash)),
32+
PSA_SUCCESS, "Failed to compare hash");
3433
}
3534

3635
ZTEST(psa_crypto_test, test_hash_sha256_multipart)
@@ -42,7 +41,7 @@ ZTEST(psa_crypto_test, test_hash_sha256_multipart)
4241
psa_hash_operation_t hash_op = psa_hash_operation_init();
4342

4443
zassert_equal(psa_hash_setup(&hash_op, PSA_ALG_SHA_256), PSA_SUCCESS,
45-
"Failed to setup hash");
44+
"Failed to setup hash");
4645

4746
while ((sizeof(plaintext) - hash_total) > stream_block_size) {
4847
zassert_equal(
@@ -55,10 +54,8 @@ ZTEST(psa_crypto_test, test_hash_sha256_multipart)
5554
PSA_SUCCESS, "Failed to update hash");
5655

5756
zassert_equal(psa_hash_finish(&hash_op, hash_buf, sizeof(hash_buf), &hash_len), PSA_SUCCESS,
58-
"Failed to finish hash");
59-
57+
"Failed to finish hash");
6058
zassert_equal(hash_len, sizeof(expect_sha256_hash), "Hash length mismatch");
61-
6259
zassert_mem_equal(hash_buf, expect_sha256_hash, sizeof(expect_sha256_hash),
63-
"Hash mismatch");
64-
}
60+
"Hash mismatch");
61+
}

0 commit comments

Comments
 (0)