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
1010const 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 };
1212const 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 };
1414const uint8_t aes_ad_buf [] = {0x5c , 0x65 , 0xd4 , 0xf2 , 0x61 , 0xd2 , 0xc5 , 0x4f , 0xfe , 0x6a };
1515const uint8_t aes_plaintext [] = {0x8d , 0x6c , 0x08 , 0x44 , 0x6c , 0xb1 , 0x0d , 0x9a , 0x20 , 0x75 };
1616
1717const 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 };
2121const uint8_t chachapoly_nonce_buf [] = {0x07 , 0x00 , 0x00 , 0x00 , 0x40 , 0x41 ,
2222 0x42 , 0x43 , 0x44 , 0x45 , 0x46 , 0x47 };
2323const 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 };
2525const 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,25 +62,23 @@ 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-
7675 zassert_equal (psa_aead_decrypt (key_id , alg , aes_nonce_buf , sizeof (aes_nonce_buf ),
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" );
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" );
8079
8180 zassert_equal (out_len , sizeof (aes_plaintext ));
8281 zassert_mem_equal (decrypted , aes_plaintext , sizeof (aes_plaintext ));
83-
8482 zassert_equal (psa_destroy_key (key_id ), PSA_SUCCESS , "Failed to destroy key" );
8583}
8684
@@ -103,21 +101,21 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
103101 psa_set_key_algorithm (& attributes , alg );
104102
105103 zassert_equal (psa_import_key (& attributes , aes_key_buf , sizeof (aes_key_buf ), & key_id ),
106- PSA_SUCCESS , "Failed to import key" );
104+ PSA_SUCCESS , "Failed to import key" );
107105
108106 zassert_equal (psa_aead_encrypt (key_id , alg , aes_nonce_buf , sizeof (aes_nonce_buf ),
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" );
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" );
113111
114112 zassert_equal (out_len , sizeof (expect_cipher_tag_buf ));
115113 zassert_mem_equal (cipher_tag_buf , expect_cipher_tag_buf , sizeof (expect_cipher_tag_buf ));
116114
117115 zassert_equal (psa_aead_decrypt (key_id , alg , aes_nonce_buf , sizeof (aes_nonce_buf ),
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" );
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" );
121119
122120 zassert_equal (out_len , sizeof (aes_plaintext ));
123121 zassert_mem_equal (decrypted , aes_plaintext , sizeof (aes_plaintext ));
@@ -130,7 +128,6 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
130128 uint8_t cipher_tag_buf [130 ]; /* Ciphertext + Tag */
131129 uint8_t decrypted [sizeof (chachapoly_plaintext )] = {0 };
132130 size_t out_len ;
133-
134131 psa_key_id_t key_id ;
135132 psa_key_attributes_t attributes = PSA_KEY_ATTRIBUTES_INIT ;
136133 psa_algorithm_t alg = PSA_ALG_CHACHA20_POLY1305 ;
@@ -140,28 +137,27 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
140137 psa_set_key_algorithm (& attributes , alg );
141138
142139 zassert_equal (psa_import_key (& attributes , chachapoly_key_buf , sizeof (chachapoly_key_buf ),
143- & key_id ),
144- PSA_SUCCESS , "Failed to import key" );
140+ & key_id ),
141+ PSA_SUCCESS , "Failed to import key" );
145142
146143 zassert_equal (psa_aead_encrypt (key_id , alg , chachapoly_nonce_buf ,
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" );
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" );
152149
153150 zassert_equal (out_len , sizeof (chachapoly_expect_cipher_tag_buf ));
154151 zassert_mem_equal (cipher_tag_buf , chachapoly_expect_cipher_tag_buf ,
155- sizeof (chachapoly_expect_cipher_tag_buf ));
152+ sizeof (chachapoly_expect_cipher_tag_buf ));
156153
157154 zassert_equal (psa_aead_decrypt (key_id , alg , chachapoly_nonce_buf ,
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" );
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" );
162159
163160 zassert_equal (out_len , sizeof (chachapoly_plaintext ));
164161 zassert_mem_equal (decrypted , chachapoly_plaintext , sizeof (chachapoly_plaintext ));
165-
166162 zassert_equal (psa_destroy_key (key_id ), PSA_SUCCESS , "Failed to destroy key" );
167163}
0 commit comments