@@ -95,10 +95,19 @@ int AesCtrEncrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
9595 if (ret != 0 )
9696 return -1040 ;
9797
98+ /* inits aes structure */
99+ ret = wc_AesInit (aes , NULL , INVALID_DEVID );
100+ if (ret != 0 ) {
101+ printf ("AesInit returned: %d\n" , ret );
102+ return -1001 ;
103+ }
104+
98105 /* sets key */
99106 ret = wc_AesSetKey (aes , key , size , iv , AES_ENCRYPTION );
100- if (ret != 0 )
107+ if (ret != 0 ) {
108+ printf ("SetKey returned: %d\n" , ret );
101109 return -1001 ;
110+ }
102111
103112 /* encrypts the message to the output based on input length + padding */
104113 ret = wc_AesCtrEncrypt (aes , output , input , length );
@@ -164,11 +173,20 @@ int AesCtrDecrypt(Aes* aes, byte* key, int size, FILE* inFile, FILE* outFile)
164173 if (ret != 0 )
165174 return -1050 ;
166175
176+ /* inits aes structure */
177+ ret = wc_AesInit (aes , NULL , INVALID_DEVID );
178+ if (ret != 0 ) {
179+ printf ("AesInit returned: %d\n" , ret );
180+ return -1002 ;
181+ }
182+
167183 /* sets key */
168184 /* decrypt uses AES_ENCRYPTION */
169185 ret = wc_AesSetKey (aes , key , size , iv , AES_ENCRYPTION );
170- if (ret != 0 )
186+ if (ret != 0 ) {
187+ printf ("SetKey returned: %d\n" , ret );
171188 return -1002 ;
189+ }
172190
173191 ret = wc_AesCtrEncrypt (aes , output , c , cSz );
174192 if (ret != 0 )
0 commit comments