@@ -110,15 +110,18 @@ void cbc_mode(void)
110
110
encrpt .out_buf_max = sizeof (encrypted );
111
111
encrpt .out_buf = encrypted ;
112
112
113
- cipher_cbc_op (& ini , & encrpt , iv );
113
+ if (cipher_cbc_op (& ini , & encrpt , iv )) {
114
+ SYS_LOG_ERR ("CBC mode ENCRYPT - Failed" );
115
+ goto out ;
116
+ }
114
117
115
118
if (memcmp (encrpt .out_buf , ciphertext , sizeof (ciphertext ))) {
116
- SYS_LOG_ERR ("cbc mode ENCRYPT - Mismatch between expected and "
119
+ SYS_LOG_ERR ("CBC mode ENCRYPT - Mismatch between expected and "
117
120
"returned cipher text" );
118
121
goto out ;
119
122
}
120
123
121
- SYS_LOG_INF ("cbc mode ENCRYPT - Match" );
124
+ SYS_LOG_INF ("CBC mode ENCRYPT - Match" );
122
125
cipher_free_session (dev , & ini );
123
126
124
127
if (cipher_begin_session (dev , & ini , CRYPTO_CIPHER_ALGO_AES ,
@@ -133,15 +136,18 @@ void cbc_mode(void)
133
136
decrypt .out_buf_max = sizeof (decrypted );
134
137
135
138
/* TinyCrypt keeps IV at the start of encrypted buffer */
136
- cipher_cbc_op (& ini , & decrypt , encrypted );
139
+ if (cipher_cbc_op (& ini , & decrypt , encrypted )) {
140
+ SYS_LOG_ERR ("CBC mode DECRYPT - Failed" );
141
+ goto out ;
142
+ }
137
143
138
144
if (memcmp (decrypt .out_buf , plaintext , sizeof (plaintext ))) {
139
- SYS_LOG_ERR ("cbc mode DECRYPT - Mismatch between plaintext and "
145
+ SYS_LOG_ERR ("CBC mode DECRYPT - Mismatch between plaintext and "
140
146
"decrypted cipher text" );
141
147
goto out ;
142
148
}
143
149
144
- SYS_LOG_INF ("cbc mode DECRYPT - Match" );
150
+ SYS_LOG_INF ("CBC mode DECRYPT - Match" );
145
151
out :
146
152
cipher_free_session (dev , & ini );
147
153
}
@@ -201,15 +207,18 @@ void ctr_mode(void)
201
207
encrpt .out_buf_max = sizeof (encrypted );
202
208
encrpt .out_buf = encrypted ;
203
209
204
- cipher_ctr_op (& ini , & encrpt , iv );
210
+ if (cipher_ctr_op (& ini , & encrpt , iv )) {
211
+ SYS_LOG_ERR ("CTR mode ENCRYPT - Failed" );
212
+ goto out ;
213
+ }
205
214
206
215
if (memcmp (encrpt .out_buf , ctr_ciphertext , sizeof (ctr_ciphertext ))) {
207
- SYS_LOG_ERR ("ctr mode ENCRYPT - Mismatch between expected "
216
+ SYS_LOG_ERR ("CTR mode ENCRYPT - Mismatch between expected "
208
217
"and returned cipher text" );
209
218
goto out ;
210
219
}
211
220
212
- SYS_LOG_INF ("ctr mode ENCRYPT - Match" );
221
+ SYS_LOG_INF ("CTR mode ENCRYPT - Match" );
213
222
cipher_free_session (dev , & ini );
214
223
215
224
if (cipher_begin_session (dev , & ini , CRYPTO_CIPHER_ALGO_AES ,
@@ -218,21 +227,23 @@ void ctr_mode(void)
218
227
return ;
219
228
}
220
229
221
-
222
230
decrypt .in_buf = encrypted ;
223
231
decrypt .in_len = sizeof (encrypted );
224
232
decrypt .out_buf = decrypted ;
225
233
decrypt .out_buf_max = sizeof (decrypted );
226
234
227
- cipher_ctr_op (& ini , & decrypt , iv );
235
+ if (cipher_ctr_op (& ini , & decrypt , iv )) {
236
+ SYS_LOG_ERR ("CTR mode DECRYPT - Failed" );
237
+ goto out ;
238
+ }
228
239
229
240
if (memcmp (decrypt .out_buf , plaintext , sizeof (plaintext ))) {
230
- SYS_LOG_ERR ("ctr mode DECRYPT - Mismatch between plaintext "
241
+ SYS_LOG_ERR ("CTR mode DECRYPT - Mismatch between plaintext "
231
242
"and decypted cipher text" );
232
243
goto out ;
233
244
}
234
245
235
- SYS_LOG_INF ("ctr mode DECRYPT - Match" );
246
+ SYS_LOG_INF ("CTR mode DECRYPT - Match" );
236
247
out :
237
248
cipher_free_session (dev , & ini );
238
249
}
@@ -303,7 +314,10 @@ void ccm_mode(void)
303
314
ccm_op .ad_len = sizeof (ccm_hdr );
304
315
ccm_op .pkt = & encrpt ;
305
316
306
- cipher_ccm_op (& ini , & ccm_op , ccm_nonce );
317
+ if (cipher_ccm_op (& ini , & ccm_op , ccm_nonce )) {
318
+ SYS_LOG_ERR ("CCM mode ENCRYPT - Failed" );
319
+ goto out ;
320
+ }
307
321
308
322
if (memcmp (encrpt .out_buf , ccm_expected , sizeof (ccm_expected ))) {
309
323
SYS_LOG_ERR ("CCM mode ENCRYPT - Mismatch between expected "
0 commit comments