@@ -55,6 +55,7 @@ This code assumes at least one is enabled
5555int wc_tsip_MakeRsaKey (int size , void * ctx )
5656{
5757 e_tsip_err_t ret ;
58+ int wcRet = WC_HW_E ;
5859 TsipUserCtx * info = (TsipUserCtx * )ctx ;
5960#if defined(TSIP_RSAES_1024 ) && TSIP_RSAES_1024 == 1
6061 tsip_rsa1024_key_pair_index_t * tsip_pair1024_key = NULL ;
@@ -148,6 +149,7 @@ int wc_tsip_MakeRsaKey(int size, void* ctx)
148149 info -> keyflgs_crypt .bits .rsapri1024_key_set = 1 ;
149150 info -> keyflgs_crypt .bits .rsapub1024_key_set = 1 ;
150151 info -> wrappedKeyType = TSIP_KEY_TYPE_RSA1024 ;
152+ wcRet = 0 ;
151153#endif
152154 }
153155 else if (size == 2048 ) {
@@ -191,13 +193,31 @@ int wc_tsip_MakeRsaKey(int size, void* ctx)
191193 info -> keyflgs_crypt .bits .rsapri2048_key_set = 1 ;
192194 info -> keyflgs_crypt .bits .rsapub2048_key_set = 1 ;
193195 info -> wrappedKeyType = TSIP_KEY_TYPE_RSA2048 ;
196+ wcRet = 0 ;
194197#endif
195198 }
196199 }
200+ else {
201+ /* hardware key generation failed; free the key pair buffer that
202+ * was allocated above so it does not leak, and report the error */
203+ WOLFSSL_MSG_EX ("TSIP RSA key generation failed: %d" , ret );
204+ #if defined(TSIP_RSAES_1024 ) && TSIP_RSAES_1024 == 1
205+ XFREE (tsip_pair1024_key , NULL , DYNAMIC_TYPE_RSA_BUFFER );
206+ #endif
207+ #if defined(TSIP_RSAES_2048 ) && TSIP_RSAES_2048 == 1
208+ XFREE (tsip_pair2048_key , NULL , DYNAMIC_TYPE_RSA_BUFFER );
209+ #endif
210+ wcRet = WC_HW_E ;
211+ }
197212 tsip_hw_unlock ();
198213 }
214+ else {
215+ /* could not obtain the TSIP hardware lock */
216+ WOLFSSL_MSG_EX ("TSIP hardware lock failed: %d" , ret );
217+ wcRet = WC_HW_E ;
218+ }
199219
200- return 0 ;
220+ return wcRet ;
201221}
202222
203223/* Generate TSIP key index if needed
@@ -260,7 +280,9 @@ int wc_tsip_RsaFunction(wc_CryptoInfo* info, TsipUserCtx* tuc)
260280 return BAD_FUNC_ARG ;
261281 }
262282
263- if (tsip_RsakeyImport (tuc ) == 0 ) {
283+ ret = tsip_RsakeyImport (tuc );
284+
285+ if (ret == 0 ) {
264286 type = info -> pk .rsa .type ;
265287 keySize = (int )tuc -> wrappedKeyType ;
266288
@@ -364,7 +386,10 @@ int wc_tsip_RsaVerifyPkcs(wc_CryptoInfo* info, TsipUserCtx* tuc)
364386 ret = CRYPTOCB_UNAVAILABLE ;
365387 }
366388
367- if (tsip_RsakeyImport (tuc ) == 0 ) {
389+ if (ret == 0 )
390+ ret = tsip_RsakeyImport (tuc );
391+
392+ if (ret == 0 ) {
368393 hashData .pdata = (uint8_t * )info -> pk .rsa .out ;
369394 hashData .data_length = * (info -> pk .rsa .outLen );
370395 hashData .data_type =
0 commit comments