99
1010const uint8_t aes_key_buf [] = {0xea , 0x4f , 0x6f , 0x3c , 0x2f , 0xed , 0x2b , 0x9d ,
1111 0xd9 , 0x70 , 0x8c , 0x2e , 0x72 , 0x1a , 0xe0 , 0x0f };
12- const uint8_t wrapped_aes_key_buf [] = {0x52 , 0xb3 , 0x41 , 0x71 , 0xcf , 0xd6 , 0xa2 , 0x00 ,
13- 0xe6 , 0xe4 , 0x75 , 0x57 , 0xa6 , 0xe5 , 0x0a , 0x0f };
1412const uint8_t aes_nonce_buf [] = {0xf9 , 0x75 , 0x80 , 0x9d , 0xdb , 0x51 ,
1513 0x72 , 0x38 , 0x27 , 0x45 , 0x63 , 0x4f };
1614const uint8_t aes_ad_buf [] = {0x5c , 0x65 , 0xd4 , 0xf2 , 0x61 , 0xd2 , 0xc5 , 0x4f , 0xfe , 0x6a };
@@ -20,12 +18,6 @@ const uint8_t chachapoly_key_buf[] = {0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86,
2018 0x88 , 0x89 , 0x8a , 0x8b , 0x8c , 0x8d , 0x8e , 0x8f ,
2119 0x90 , 0x91 , 0x92 , 0x93 , 0x94 , 0x95 , 0x96 , 0x97 ,
2220 0x98 , 0x99 , 0x9a , 0x9b , 0x9c , 0x9d , 0x9e , 0x9f };
23- #if defined(CONFIG_TEST_WRAPPED_KEYS ) && CONFIG_TEST_WRAPPED_KEYS
24- const uint8_t wrapped_chachapoly_key_buf [] = {0x19 , 0x67 , 0x03 , 0x6a , 0x20 , 0xe6 , 0x32 , 0xed ,
25- 0x21 , 0x2a , 0x4a , 0xdc , 0x2c , 0x5f , 0x19 , 0x22 ,
26- 0x77 , 0x56 , 0x61 , 0x92 , 0x2c , 0xf3 , 0xdc , 0xe8 ,
27- 0x8e , 0x81 , 0x45 , 0x4d , 0xd6 , 0xc7 , 0x86 , 0x0b };
28- #endif
2921const uint8_t chachapoly_nonce_buf [] = {0x07 , 0x00 , 0x00 , 0x00 , 0x40 , 0x41 ,
3022 0x42 , 0x43 , 0x44 , 0x45 , 0x46 , 0x47 };
3123const uint8_t chachapoly_ad_buf [] = {0x50 , 0x51 , 0x52 , 0x53 , 0xc0 , 0xc1 ,
@@ -69,22 +61,15 @@ ZTEST(psa_crypto_test, test_aead_aes_ccm)
6961 psa_set_key_usage_flags (& attributes , PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
7062 psa_set_key_algorithm (& attributes , alg );
7163
72- #if defined(CONFIG_TEST_WRAPPED_KEYS ) && CONFIG_TEST_WRAPPED_KEYS
73- printf ("Test Wrapper keys enabled\n" );
74- psa_set_key_lifetime (& attributes , PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (
75- PSA_KEY_PERSISTENCE_VOLATILE , 1 ));
76- zassert_equal (psa_import_key (& attributes , wrapped_aes_key_buf , sizeof (wrapped_aes_key_buf ),
77- & key_id ),
78- PSA_SUCCESS , "Failed to import key" );
79- #else
8064 zassert_equal (psa_import_key (& attributes , aes_key_buf , sizeof (aes_key_buf ), & key_id ),
8165 PSA_SUCCESS , "Failed to import key" );
82- #endif
66+
8367 zassert_equal (psa_aead_encrypt (key_id , alg , aes_nonce_buf , sizeof (aes_nonce_buf ),
8468 aes_ad_buf , sizeof (aes_ad_buf ), aes_plaintext ,
8569 sizeof (aes_plaintext ), cipher_tag_buf ,
8670 sizeof (cipher_tag_buf ), & out_len ),
87- PSA_SUCCESS , "Failed to perform encrypt" );
71+ PSA_SUCCESS , "Failed to encrypt" );
72+
8873 zassert_equal (out_len , sizeof (expect_cipher_tag_buf ));
8974 zassert_mem_equal (cipher_tag_buf , expect_cipher_tag_buf , sizeof (expect_cipher_tag_buf ));
9075
@@ -95,6 +80,7 @@ ZTEST(psa_crypto_test, test_aead_aes_ccm)
9580
9681 zassert_equal (out_len , sizeof (aes_plaintext ));
9782 zassert_mem_equal (decrypted , aes_plaintext , sizeof (aes_plaintext ));
83+
9884 zassert_equal (psa_destroy_key (key_id ), PSA_SUCCESS , "Failed to destroy key" );
9985}
10086
@@ -116,25 +102,16 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
116102 psa_set_key_usage_flags (& attributes , PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
117103 psa_set_key_algorithm (& attributes , alg );
118104
119- #if defined(CONFIG_TEST_WRAPPED_KEYS ) && CONFIG_TEST_WRAPPED_KEYS
120- printf ("Test Wrapper keys enabled\n" );
121- psa_set_key_lifetime (& attributes , PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (
122- PSA_KEY_PERSISTENCE_VOLATILE , 1 ));
123- zassert_equal (psa_import_key (& attributes , wrapped_aes_key_buf , sizeof (wrapped_aes_key_buf ),
124- & key_id ),
125- PSA_SUCCESS , "Failed to import key" );
126- #else
127105 zassert_equal (psa_import_key (& attributes , aes_key_buf , sizeof (aes_key_buf ), & key_id ),
128106 PSA_SUCCESS , "Failed to import key" );
129- #endif
107+
130108 zassert_equal (psa_aead_encrypt (key_id , alg , aes_nonce_buf , sizeof (aes_nonce_buf ),
131109 aes_ad_buf , sizeof (aes_ad_buf ), aes_plaintext ,
132110 sizeof (aes_plaintext ), cipher_tag_buf ,
133111 sizeof (cipher_tag_buf ), & out_len ),
134- PSA_SUCCESS , "Failed to perform encrypt" );
112+ PSA_SUCCESS , "Failed to encrypt" );
135113
136114 zassert_equal (out_len , sizeof (expect_cipher_tag_buf ));
137-
138115 zassert_mem_equal (cipher_tag_buf , expect_cipher_tag_buf , sizeof (expect_cipher_tag_buf ));
139116
140117 zassert_equal (psa_aead_decrypt (key_id , alg , aes_nonce_buf , sizeof (aes_nonce_buf ),
@@ -144,6 +121,7 @@ ZTEST(psa_crypto_test, test_aead_aes_gcm)
144121
145122 zassert_equal (out_len , sizeof (aes_plaintext ));
146123 zassert_mem_equal (decrypted , aes_plaintext , sizeof (aes_plaintext ));
124+
147125 zassert_equal (psa_destroy_key (key_id ), PSA_SUCCESS , "Failed to destroy key" );
148126}
149127
@@ -161,33 +139,29 @@ ZTEST(psa_crypto_test, test_aead_chacha20_poly1305)
161139 psa_set_key_usage_flags (& attributes , PSA_KEY_USAGE_ENCRYPT | PSA_KEY_USAGE_DECRYPT );
162140 psa_set_key_algorithm (& attributes , alg );
163141
164- #if defined(CONFIG_TEST_WRAPPED_KEYS ) && CONFIG_TEST_WRAPPED_KEYS
165- printf ("Test Wrapper keys enabled\n" );
166- psa_set_key_lifetime (& attributes , PSA_KEY_LIFETIME_FROM_PERSISTENCE_AND_LOCATION (
167- PSA_KEY_PERSISTENCE_VOLATILE , 1 ));
168- zassert_equal (psa_import_key (& attributes , wrapped_chachapoly_key_buf ,
169- sizeof (wrapped_chachapoly_key_buf ), & key_id ),
170- PSA_SUCCESS , "Failed to import key" );
171- #else
172142 zassert_equal (psa_import_key (& attributes , chachapoly_key_buf , sizeof (chachapoly_key_buf ),
173143 & key_id ),
174144 PSA_SUCCESS , "Failed to import key" );
175- #endif
145+
176146 zassert_equal (psa_aead_encrypt (key_id , alg , chachapoly_nonce_buf ,
177147 sizeof (chachapoly_nonce_buf ), chachapoly_ad_buf ,
178148 sizeof (chachapoly_ad_buf ), chachapoly_plaintext ,
179149 sizeof (chachapoly_plaintext ), cipher_tag_buf ,
180150 sizeof (cipher_tag_buf ), & out_len ),
181- PSA_SUCCESS , "Failed to perform encrypt" );
151+ PSA_SUCCESS , "Failed to encrypt" );
152+
182153 zassert_equal (out_len , sizeof (chachapoly_expect_cipher_tag_buf ));
183154 zassert_mem_equal (cipher_tag_buf , chachapoly_expect_cipher_tag_buf ,
184155 sizeof (chachapoly_expect_cipher_tag_buf ));
156+
185157 zassert_equal (psa_aead_decrypt (key_id , alg , chachapoly_nonce_buf ,
186158 sizeof (chachapoly_nonce_buf ), chachapoly_ad_buf ,
187159 sizeof (chachapoly_ad_buf ), cipher_tag_buf , out_len ,
188160 decrypted , sizeof (decrypted ), & out_len ),
189161 PSA_SUCCESS , "Failed to decrypt" );
162+
190163 zassert_equal (out_len , sizeof (chachapoly_plaintext ));
191164 zassert_mem_equal (decrypted , chachapoly_plaintext , sizeof (chachapoly_plaintext ));
165+
192166 zassert_equal (psa_destroy_key (key_id ), PSA_SUCCESS , "Failed to destroy key" );
193167}
0 commit comments